Description
Input
Output
Sample Input
3 olleh !dlrow m‘I morf .udh I ekil .mca
Sample Output
hello world! I‘m from hdu. I like acm.
Hint
Remember to use getchar() to read ‘\n‘ after the interger T, then you may use gets() to read a line and process it.
#include <iostream> #include <cstring> using namespace std; int main() { int t,i,j,p,flag=0; char a[100000]; cin >> t; cin.get(); while (t--) { cin.getline(a,100000); for(i=0;a[i]!='\0';i++) { if(a[i]!=' ') { p=i; break; } } for (i=0;a[i]!='\0';i++) { if (a[i+1]==' ') { for (j=i;j>=p;j--) { cout << a[j]; } p=i+2; } if(a[i]==' ') { cout << " "; } } for (j=strlen(a)-1;a[j]!=' ';j--) { cout << a[j]; } cout << endl; } return 0; }
原文地址:http://blog.csdn.net/zsc2014030403015/article/details/43484553