题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062
Problem Description
Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.
Output
For each test case, you should output the text which is processed.
Sample Input
3
olleh !dlrow
m'I morf .udh
I ekil .mca
Sample Output
hello world!
I'm from hdu.
I like acm.
解题思路:问题求解的是每个句子中每个单词的反转。
AC代码一之C代码:
1 #include<bits/stdc++.h> 2 using namespace std; 3 char a[1005]; 4 int main() 5 { 6 int T,len,x,y; 7 while(cin>>T){ 8 getchar();//吃掉回车符 9 while(T--){ 10 gets(a); 11 len=strlen(a); 12 for(int i=0;i<len;++i){ 13 x=i;//标记当前单词的起始坐标 14 while(a[i]!=' ' && a[i]!='