【NEEPU OJ】1030--Reverse!

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_34072526/article/details/87864178

描述

In a legend in the country, people there always love to write words in reverse way.

But Alice is not the person of that country, so she can’t understand the words there. Can you help Alice solve the problem?

输入

The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.

Each test case contains a single line with several words. There will be at most 1000 characters in a line.

输出

For each test case, you should output the text which is processed.

输入样例 1

3
olleh !dlrow
m’I morf .upeen
I ekil .mca

输出样例 1

hello world!
I’m from neepu.
I like acm.

提示

Remember to use getchar() to read ‘\n’ after the interger T, then you may use gets() to read a line and process it.


代码

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

int main(){
    char a[1010], b[1010];
    char *p;
    int t;
    scanf("%d%*c", &t);
    while(t--){
        fill(a, a + 1000, 0);
        fill(b, b + 1000, 0);
        scanf("%[^\n]%*c", a);
        for(p = a + strlen(a); p > a; p--){
            if(*p == ' '){
                *p = '\0';
                strcat(b, p + 1);
                strcat(b, " ");
            }
        }
        strcat(b, p);
        for(p = b + strlen(b) - 1; p >= b; p--) printf("%c", *p);
        puts("");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_34072526/article/details/87864178
今日推荐