1513.K.Reversed Words SDNUOJ 1513

Description
Some aliens are learning English. They have a very strange way in writing that they revered every word in the sentence but keep all the words in common order. For example when they want to write “one two three”, they will write down “eno owt eerht”.

Now we’ve got some sentence written by these aliens, translate them! And maybe we will know some of their secrets!

Input
Multiple test cases. The first line contains a positive integer T (T <= 1000), indicating the number of test cases.

For each test cases, there will be one line contains only lower case letters and spaces. The length of each line will be no more than 10000. Test cases which are longer than 5000 will be less than 50. Continuous letters are seen as a word, words are separated by spaces. There won’t be two adjacent spaces in the input. Space won’t be the first or the last character.

Output
One line per case, the translated sentence.

Sample Input
2
eno owt eerht
abcde
Sample Output
one two three
edcba

用vector卡住了…

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
    int t;
    while(cin >> t)
    {
        getchar();
        while(t--)
        {

                char s[10005];
                gets(s);
//                cout << s << '\n';
                int len = strlen(s);
//                cout << len << '\n';
                int start = 0;
                int over;
                for(int j = 0; j <= len; j++)
                {
                    if(s[j] == ' ' || j == len)
                    {
                        for(int k = j - 1; k >= start; --k)
                        {
                            cout << s[k];
                        }
                        if(j != len)
                            cout << " ";
                        start = j + 1;
                    }
                }
                cout << '\n';

        }
    }
    return 0;
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-10 14:00
林子大了什么鸟都有啊,我觉得我说的已经很客气了,阴阳谁呢
牛客62656195...:应该不是阴阳吧?你第一次注册的时候boss就说你是牛人
点赞 评论 收藏
分享
怎么起名字:早知道就不读书了,害得我送外卖还得扶眼镜
点赞 评论 收藏
分享
05-19 15:21
已编辑
门头沟学院 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
06-23 11:28
门头沟学院 Java
牛客91966197...:也有可能是点拒绝的时候自动弹的话术
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务