您的位置:首页 > 其它

HDU 1062 Text Reverse(水~)

2015-08-29 10:46 197 查看
Description

给出一些字符串,将这些字符串中所有的单词反序后输出转化后的字符串

Input

第一行为用例组数T,每组用例占一行为一字符串

Output

对于每组用例,输出转化后的字符串

Sample Input

3

olleh !dlrow

m’I morf .udh

I ekil .mca

Sample Output

hello world!

I’m from hdu.

I like acm.

Solution

简单字符串处理,注意ungetc函数的使用,这个函数是将读入的一个或多个字符退回到输入流中

Code

#include<stdio.h>
#include<string.h>
char word[1005];
int main()
{
int n;
scanf("%d",&n);
while(scanf("%s",word)!=EOF)
{
for(int i=strlen(word)-1;i>=0;i--)
putchar(word[i]);
char c;
while(c=getchar(),c ==' '||c=='\t'||c=='\n')//空格/跳格/换行字符直接输出
putchar(c);
ungetc(c,stdin);//将读入的字符退回
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: