您的位置:首页 > 其它

1062 字符串处理 水题

2016-06-23 21:16 330 查看
Hot~~欢迎“信息学(OI)选手”——报考杭州电子科技大学!
Text Reverse
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25889    Accepted Submission(s): 10041

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.

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.

Hint

Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.

Author
Ignatius.L

Recommend


#include<stdio.h>
#include<string.h>
char c[1001];
void print(int n)
{
for(int i=1;i<=n;i++)
{
gets(c);//puts(c);
int len=strlen(c);
for(int i=0;i<len;i++)
{
if(c[i]==' ')
{
for(int j=i-1;c[j]!=' '&&j>=0;j--) putchar(c[j]);
putchar(' ');
}
if(i==len-1) for(int j=i;c[j]!=' '&&j>=0;j--) putchar(c[j]);
}
putchar('\n');
}
}
int main(void)
{
//freopen("E:\\test.txt","r",stdin);
int n;
while(~scanf("%d",&n))
{
getchar();
print(n);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: