HDU 1062 Text Reverse

来源:互联网 发布:java实现文件加密 编辑:程序博客网 时间:2024/05/17 17:46

Problem Description

Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.

Input

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.

Output

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

Sample Input

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

Sample Output

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

题目大意:

先输入一个n,表示有n组测试数据。输入为一个字符串,但是这个字符串是逆向的,你需要将更改好的字符串输出。

c++

#include <iostream>#include<cstring>#include<cstdio>using namespace std;int main(){    int a,b,c,d,e;    char m[1000];    cin>>a;    getchar();    while(a--)    {        gets(m);      //gets可以读入空格        b=strlen(m);        e=0;        //e用来存放开始与空格后一位        while(1)        {            for(c=e;c<b;c++)            {                if(m[c]==' ')                    break;            }            for(d=c-1;d>=e;d--)  //将其倒着输出            {                cout<<m[d];            }            if(c>=b)                break;            e=c+1;            cout<<" ";        }        cout<<endl;    }    return 0;}
0 0