1626: Reverse words
Time Limit: 1 Sec Memory Limit: 32 MBCommits: 31 Solved: 10
Your Question's Status: Completed
[ Commit ][ Status ][ Discussion Board ]
Topic description
Restore each reversed word in the input.
enter
The input contains sets of test cases. The first line is an integer T representing the number of test cases, followed by T test cases.
Each test example occupies one line and contains multiple words. A line can have a maximum of 1000 characters.
Each test example occupies one line and contains multiple words. A line can have a maximum of 1000 characters.
output
For each test case, you should output the converted text.
sample input
2
i evol !anihC
olleh !dlrow
Sample output
i love China!
hello world!
source
Why do you want to post it, because I made a mistake several times ( ), I was not careful, I accidentally put getchar() in it,,,
#include<stdio.h> #include<string.h> int main(){ int T,i,j,k; char str[1010]; scanf("%d",&T); getchar(); while(T--){ gets(str); int len = strlen (str); for(i=0;i<len;i++){ if(str[i]==' '){ printf("%c",str[i]); continue; } else{ for(j=i;;j++){ if(str[j]==' '||str[j]=='\0'){ break; } } for(k=j-1;k>=i;k--){ printf("%c",str[k]); } i=j-1; } } printf("\n"); } return 0; }