HDU1062:Text Reverse
2016-02-21 16:26
281 查看
[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.
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.
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main() { int n,i,k1,k2; char data[9999]; cin>>n; getchar(); while(n--) { k1=0;k2=0; gets(data); for(i=0;i<=strlen(data);i++) { if(data[i]==' '||data[i]=='\0')//找空格,为了找单词 { k2=i-1;//是空格前面那个词的下标 for(k2;k2>=k1;k2--)//从K2一直打到k1这个词 cout<<data[k2]; k1=i+1;//k1是下一个单词的开头的下标 if(data[i]==' ') cout<<" "; if(data[i]=='\0') cout<<endl; } } } return 0; }
相关文章推荐
- http://blog.csdn.net/antjumper/article/details/39479187
- WinCE 下实现 ping 功能
- Linux 之 awk 命令
- MySQL连接查询
- 飞思卡尔9S12X系列双核中的协处理器XGATE使用方法
- 转:Spring 资源访问剖析和策略模式应用
- 支付宝集成
- ZOJ-3203-Light Bulb【6th浙江省赛】【数学公式】【三分】
- 面向对象5
- POJ 3267 The Cow Lexicon(DP单词匹配)
- 迟来的2015总结
- 构建单页Web应用
- 简单的音乐播放器
- WP8 电话本编程
- 51 nod 1181 质数中的质数(质数筛法)
- Android问题集(八)——
- PowerDNS简单教程(1):安装篇
- 面向对象之多态
- 循环结构(while语句)
- ZOJ-3202-Second-price Auction【6th浙江省赛】