首页 > 其他 > 详细

字符串反转,栈模拟(ZOJ1151)

时间:2016-04-20 21:35:57      阅读:329      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151

 

这里可以用栈模拟,也可以用STL,reverse();函数。

但是我这里用栈模拟,PE了,了解一下这个做法吧。

 

技术分享

 

技术分享
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        int t,j=1;
        char k;
        cin >> t;
        getchar();
        while (1)
        {
            if (j > t)
                break;
            string p;
            cin >> p;
            reverse(p.begin(), p.end());
            cout << p;
            k = getchar();
            if (k == )
                cout <<" ";
            if (k == \n)
            {
                j++;
                cout << endl;
            }
        }
        if (n)
            cout << endl;
    }
    return 0;
}
View Code

 

字符串反转,栈模拟(ZOJ1151)

原文:http://www.cnblogs.com/TreeDream/p/5414172.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!