题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062
解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符。
1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #include<deque> 7 #include<cstdlib> 8 using namespace std; 9 10 const int maxn = 1000 + 5; 11 12 char temp[maxn],str[maxn]; 13 14 int main() 15 { 16 int T; 17 scanf("%d",&T); 18 getchar(); 19 while(T--) 20 { 21 gets(str); 22 int len = strlen(str),f = 0,flag = 1; 23 for(int i = 0;i < len;++i) 24 { 25 if(str[i] != ' ') 26 temp[f++] = str[i]; 27 if(str[i] == ' ' || i == len - 1) 28 { 29 temp[f] = NULL; 30 reverse(temp,temp+f); 31 printf("%s",temp); 32 if(i != len - 1 || str[i] == ' ') printf(" "); 33 f = 0; 34 } 35 } 36 puts(""); 37 } 38 return 0; 39 }