题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062
利用一个for循环实现每一个单词的倒序输出,我们在实现遇到空格然后倒序输出的时候我们也应该考虑字符串的最后一个元素是不是空格,以及每个单词之间或者末尾 有几个空格,有几个空格我们就应该输出多少空格,比如 abc---------def-zxc 我们应该使其输出成 cba---------fed-cxz “ - ” 表示空格。
#include<stdio.h>
#include<string.h>
int main()
{
int a;
char b[1000];
while(scanf("%d",&a)!=EOF){
getchar();
int c,i,e,f=-1;
while(a--){
gets(b);
c=strlen(b);
for(i=0;i<=c;i++){
if(b[i]==' '||i==c){
for(e=i-1;e>=0&&e!=f;e--)
putchar(b[e]);
f=i;
if(i!=c) putchar(' ');
}
}
printf("\n");
}
}
return 0;
}