杭电 1062 Text Reverse
2013-04-17 17:31
239 查看
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11832 Accepted Submission(s): 4487
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, you should output the text which is processed.
[align=left]Sample Input[/align]
3
olleh !dlrow
m'I morf .udh
I ekil .mca
[align=left]Sample Output[/align]
hello world!
I'm from hdu.
I like acm.
Hint
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.
[align=left]Author[/align]
Ignatius.L
这个题调试了一段时间才AC,提交了三四次,都是PE!
这个题应该注意什么呢?每个单词之间可以有一个或多个空格,如果用scanf去获得每一行的一个单词,在输出的时候,就可能在应该输出多个空格的地方,只输出了一个空格!导致输出格式的错误!另外,我提交的代码AC了,说明oj提供给这个题测试样例的每一行的单词之间应该是没有制表符的!
以下是代码:
View Code
#include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc, char *argv[]) { int n, Len, i, flag, j; char s[1005]; scanf( "%d", &n ); getchar(); //printf( "%d\n", n ); while( n-- ) { gets(s); //printf( "%s\n",s ); //getchar(); Len = strlen(s); //printf( "%d\n", Len ); flag = 0; for( i = 0; i < Len; i++ ) if( s[i] == ' ' ) { for( j = i-1; j >= flag; j-- ) printf( "%c", s[j] ); flag = i+1; printf( "%c",s[i] ); } else if( i == Len-1 ) { for( j = i; j >= flag; j-- ) printf( "%c", s[j] ); flag = i+1; } printf( "\n" ); } s//ystem("PAUSE"); return 0; }
相关文章推荐
- 杭电1062 之 Text Reverse
- Text Reverse(杭电oj1062)
- 杭电 HDU 1062 Text Reverse
- 杭电OJ1062-Text Reverse
- 杭电oj1062 Text Reverse
- 杭电水题--Text Reverse 1062
- 【杭电】[1062]Text Reverse
- 杭电ACM 1062: Text Reverse
- 杭电OJ-1062_Text Reverse
- 杭电1062-Text Reverse
- 杭电ACM 1062: Text Reverse
- 杭电acm刷题(3):1062,Text Reverse 标签: 杭电acm 2017-05-15 08:26 126人阅读 评论(0)
- 杭电acm刷题(3):1062,Text Reverse
- 杭电1062 Text Reverse
- 杭电OJ1062 Text Reverse
- 杭电1062
- HDU 1062 Text Reverse(水~)
- hdu 1062 Text Reverse
- HDU1062 Text Reverse
- hdu 1062 text reverse