Text Reverse

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.
 1 #include<iostream>
 2 using namespace std;
 3 int main()
 4 {
 5     int t,i=0,j=0;
 6     char word[1000];
 7     cin>>t;
 8     getchar();
 9     while(t--)
10     {
11         gets(word);
12         int i,s,p;
13         for(i=0;i<strlen(word);++i)
14         {
15             s=i;
16             while(word[i]!=‘ ‘&&word[i]!=‘\0‘) ++i;
17             p=i-1;
18             for(;p>=s;--p) cout<<word[p];
19             if(word[i]==‘ ‘)
20                 cout<<" ";
21         }
22         cout<<endl;
23     }
24     return 0;
25 }
时间: 2024-11-03 03:26:24

Text Reverse的相关文章

hdu 1062 Text Reverse 字符串反转

Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18240    Accepted Submission(s): 6900 Problem Description Ignatius likes to write words in reverse way. Given a single line of text

Text Reverse(杭电oj1062)

Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17702    Accepted Submission(s): 6717 Problem Description Ignatius likes to write words in reverse way. Given a single line of text

HDU 1062.Text Reverse【栈或数组或字符串流】【字符处理】【8月30】

Text Reverse 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 lin

ACM step 1.2.2 Text Reverse

gnatius 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. 一个简单的回文输出..然后请原谅我的冗长的代码,之前很久没写程序了.. // //  main.cpp //  hdu1.2.2 // //  Created by wuxi on 1

HDOJ/HDU 1062 Text Reverse(字符串翻转~)

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 inpu

hdu1062 text reverse

咳咳,这个是为了赶量 需要注意的就是输入方式,别的也没什么难点 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 c

杭电oj1062 Text Reverse

Tips:使用一个临时数组c[1000] ,将输入的数据一边复制一边处理,碰到空格时就将前面的字符反向输出即可 1 #include<stdio.h> 2 #include<string.h> 3 ///使用一个临时数组c[1000] ,将输入的数据一边复制一边处理 4 void reverse(char s[]){ 5 char c[1000]; 6 int i,j,k; 7 for(i=0,j=0;i<strlen(s);i++){ 8 c[j++]=s[i]; 9 if

HDU 1062 Text Reverse(水题,字符串处理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #include<deque> 7 #include&

HDU 1062 Text Reverse

字符串反转:每个单词反转,然后输出. PE做法:所有单词反转并写入另一个数组中,附代码 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int N=1005; 6 int main() { 7 char ol[N],no[N]; 8 int n; 9 // freopen("C:\\CODE\\in.txt",