Memory Limit: 131072KB | 64bit IO Format: %lld & %llu |
Description
Input
Output
Sample Input
3 4 I am a man 4 I will AC it 3 I love ACM
Sample Output
I ma a nam I lliw CA ti I evol MCA
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=14218
题解:将每个单词倒置,可以用char数组,然后用空格分隔,这里用的是string和stringstream。
#include <cstdio> #include <iostream> #include <string> #include <sstream> #include <cstring> #include <stack> #include <queue> #include <algorithm> #include <cmath> #include <map> using namespace std; //#define LOCAL int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL //Start int N; cin>>N; while(N--) { int t; cin>>t; getchar(); string s,sss; getline(cin,s); stringstream ss(s); int i=0; while(ss>>sss) { string::iterator it=sss.end()-1; if(i++!=0)printf(" "); while(it!=sss.begin()) { cout<<*it; it--; } cout<<*it; } printf("\n"); } return 0; }
原文:http://www.cnblogs.com/gpsx/p/5160685.html