xynuoj 1626: Reverse words

1626: Reverse words

Time Limit:  1 Sec   Memory Limit:  32 MB
Commits:  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.

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 ( Wronged), 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;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326501562&siteId=291194637