Text Reverse

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.

 输入输出的练习

#include<string>
#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{
    string s;
    int l,i,j,k,n;
    cin >> n;
    getchar();
    while(n--)
    {
        getline(cin,s);
        l = s.length();
        for(k=0,j=-1;k<=l;k++)
        {
            if(s[k]==' '||k==l)
            {
                for(i=k-1;i>j;i--)
                {
                    cout << s[i];
                }
                if(k!=l)
                    cout <<' ';
                else
                    cout <<endl;
                j=k;
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/gaosshun/p/3541648.html