【HDOJ】1062 Text Reverse

it2025-11-13  7

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.

 

#include<iostream>#include<string>using namespace std;void main(){ int T; while (cin>>T) { getchar();

for (int i = 0; i < T; i++) { string str; getline(cin, str); int end = 0,top = 0; while (str[end] != '\0') { if (str[end]==' ') { for (int i = end-1; i >=top; i--) { cout << str[i]; }

cout << str[end]; top = end + 1; } end++; } if (str[end]=='\0') { for (int i = end-1; i >=top-1; i--) { cout << str[i]; } } cout << endl; } }}

转载于:https://www.cnblogs.com/ruoh3kou/p/7105794.html

相关资源:数据结构—成绩单生成器
最新回复(0)