题目:http://acm.hdu.edu.cn/showproblem.php?pid=1062
题目很简单,不多说
下面是自己的代码:
#include<bits/stdc++.h>
#define INF 1e18
#define inf 1e9
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std ;
typedef long long ll;
typedef unsigned long long ull;
const int _max =1050;
int main(){
int t;
char c,str[_max];
cin>>t;
getchar();
while(t--){
gets(str);
string s = str;
string ch ,ans="";
int len = s.length();
int begin = 0;
for(int i = 0 ; i < len ; i++){
if(s[i] == ' '){
ch = s.substr(begin,i-begin);
begin = i+1;
reverse(ch.begin(),ch.end());
ans += ch;
ans += " ";
}
}
ch = s.substr(begin,len-begin);
reverse(ch.begin(),ch.end());
ans += ch;
cout<<ans<<endl;
}
return 0;
}