Text Reverse

题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1062

#include <iostream>

using namespace std;
char* reverse(char *s,int begin,int end)
{
char temp;
while(begin <= end)
{
temp = s[begin];
s[begin] = s[end];
s[end] = temp;
begin++;
end--;
}
return s;
}
int main()
{
int T,begin,end;
int length;
int i,j;
char s[1002];
char temp;
while(scanf("%d",&T)!=EOF)
{
getchar();
for(j =0;j <T;j++)
{
gets(s);
length = strlen(s);
begin =0;
end =0;
for(i=0;i < length;i++)
{
if(s[i] !=' ') //寻找单词起点
{
begin = i;
for(;i<length;i++)
{
if(s[i]==' ') //单词尾点
{
end = i-1;
break;
}
}
if(i>=length)//最后一个单词
end = length-1;
reverse(s,begin,end);
}
}
printf("%s
",s);
}
}
return 0;
}

原文地址:https://www.cnblogs.com/cheng07045406/p/3174837.html