hdu1062
来源:互联网 发布:淘宝云客服论坛 编辑:程序博客网 时间:2024/06/05 20:44
Text Reverse
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 25 Accepted Submission(s) : 13
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
3olleh !dlrowm'I morf .udhI 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.[/hint]
很简单的字符串颠倒的问题主要需要注意的只是在操作的时候是对每个单词进行颠倒的操作,不是整体的。代码如下
#include <cstdio>#include <iostream>#include <cstring>using namespace std;#define maxn 1100char a[maxn];void change(int first,int last)//交换区间first 到last之间的值{for(int i=first;i<(first+last)/2;i++){int c = a[i];a[i] = a[(first+last)-i-1];a[(first+last)-i-1] = c;}}int main(){int n;scanf("%d",&n);getchar();while(n--){gets(a);int len = strlen(a);int s=0,e=0;for(int i=0;i<len;i++){if(a[i]==' '){e = i;change(s,e);s=e+1;}}if(a[len-1]!=' '){e = len;change(s,e);}printf("%s\n",a); } return 0;}
0 0
- hdu1062
- hdu1062
- hdu1062
- hdu1062(Text Reverse)
- HDU1062:Text Reverse
- Text Reverse hdu1062 水题
- hdu1062字符串处理
- hdu1062 Text Reverse
- HDU1062(字符串处理)
- scanf 与 gets HDU1062
- HDU1062 Text Reverse
- hdu1062:Text Reverse
- HDU1062 Text Reverse
- Hdu1062 Text Reverse
- hdu1062 - Text Reverse
- hdu1062-Text Reverse
- HDU1062 Text Reverse
- HDU1062 Text Reverse
- 羇芀艿蒂蚃腿膁蒇袂罿薆薃
- 膅莂莅蕿膁莁薇螄肇莁蚀蚇
- [LeetCode]Reorder List
- 十进制转十六进制
- linux
- hdu1062
- Spring XML配置--使用注解装配(@Atutowired、@Inject、@Resource)
- 逃出你的肖申克(二)(三):笔记
- 【C++练习】斐波那契数列
- HtmlCXX 解析html
- Shell 通配符、元字符、转义符
- 难度0 字符串逆序输出
- HDU 2818 Building Block
- Java继承