hdu-1062 Text Reverse
2016-07-12 20:41
453 查看
Text Reverse
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 25953 Accepted Submission(s): 10068
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.
题目看清楚,问题其实还不大,不是将整个字符串反转过来,而是一个字符串中包含了一个或者多个单词,将其中的各个单词反转过来顺序就对了,代码如下:
// // main.cpp // hdu1062 // // Created by Morris on 16/7/12. // Copyright © 2016年 Morris. All rights reserved. // #include <cstdio> #include <cstring> namespace { using std::scanf; using std::printf; using std::getchar; using std::gets; using std::strlen; } int main(int argc, const char *argv[]) { int n; char word[100]; char str[2048]; int i, j, k, l, m; while (~scanf("%d", &n)) { getchar(); for (i = 0; i < n; ++i) { gets(str); j = k = l = 0; while (k < strlen(str)) { if (str[k] != ' ') { word[l++] = str[k]; } else { for (m = l - 1; m >= 0; --m) { printf("%c", word[m]); } printf(" "); l = 0; } if (k == strlen(str) - 1) { for (m = l - 1; m >= 0; --m) { printf("%c", word[m]); } printf("\n"); } ++k; } } } return 0; }
相关文章推荐
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- 计算字符串最后一个单词长度
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- 矩阵的乘法操作
- 蚂蚁爬行问题
- 蚂蚁爬行问题
- 求两个数的最大公约数【ACM基础题】
- 打印出二进制中所有1的位置
- 杭电题目---一只小蜜蜂
- HDOJ 1002 A + B Problem II (Big Numbers Addition)
- 初学ACM - 半数集(Half Set)问题 NOJ 1010 / FOJ 1207
- 初学ACM - 组合数学基础题目PKU 1833
- POJ ACM 1002