题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062
大概意思就是给一个字符串,其中每个单词都是倒过来的,让你恢复正确的。
确定字符串中的空格位置就可以了。
#include <bits/stdc++.h>
using namespace std;
char x[1005];
void show(int a,int b)
{
if(a!=-1)
cout<<' ';
for(b--;b>a;b--)
cout<<x[b];
}
void showend(int a,int b)
{
if(a!=-1)
cout<<' ';
for(;b>a;b--)
cout<<x[b];
}
int main()
{
int t;cin>>t;
getchar();//吸收空格
while(t--)
{
cin.getline(x,1005,'\n');
int s,e=-1;
for(int i=0;i<strlen(x);i++)
{
if(x[i]==' ')
{
s=e;
e=i;
show(s,e);
}
}
s=e;
e=strlen(x)-1;
showend(s,e);
cout<<endl;
}
}