Text Reverse&&http://acm.hdu.edu.cn/showproblem.php?pid=1062
2012-07-21 11:24
597 查看
[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.
这一题真他妈的恶心,本来是可以用sstream库函数的但是由于输入的字符串可能有多个空格也的输出,却不能用郁闷。。AC代码:
第一次代码:
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.
这一题真他妈的恶心,本来是可以用sstream库函数的但是由于输入的字符串可能有多个空格也的输出,却不能用郁闷。。AC代码:
#include<iostream> #include<cstring> #include<sstream> using namespace std; int main(){ int t; char a[1005],b[1005]; scanf("%d%*c",&t); while(t--){ gets(a); int i=0; while(a[i]){ int k=0; if(a[i]==' '){ printf(" "); i++; } while(a[i]!=' ' && a[i]) b[k++]=a[i++]; b[k]='\0'; for(int j=strlen(b)-1;j>=0;j--) printf("%c",b[j]); } puts(""); } return 0; }
第一次代码:
#include<iostream> #include<set> #include<cmath> #include<string.h> #include<string> #include<algorithm> #include<sstream> using namespace std; int main() { int T; scanf("%d",&T); char ch=getchar(); for(int k=1;k<=T;++k) { string s,str; getline(cin,s); istringstream stream(s); int tot=0; while(stream>>str) { if(tot++) str+=" "; reverse(str.begin(),str.end()); cout<<str; } cout<<endl; }return 0; }
相关文章推荐
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=791&pid=1001&ojid=0
- Red and Black&&http://acm.hdu.edu.cn/showproblem.php?pid=1312
- http://acm.hdu.edu.cn/showproblem.php?pid=2795&&线段树之求最小区间端点值
- Number Sequence&&http://acm.hdu.edu.cn/showproblem.php?pid=1005
- 完数 &&http://acm.hdu.edu.cn/showproblem.php?pid=1406
- Clairewd’s message&&http://acm.hdu.edu.cn/showproblem.php?pid=4300
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?cid=963&pid=1019&ojid=1
- Trouble&&http://acm.hdu.edu.cn/showproblem.php?pid=4334
- http://acm.hdu.edu.cn/webcontest/contest_showproblem.php?pid=1004&ojid=1&cid=6866&hide=1&problem=Pro
- Holedox Eating &&http://acm.hdu.edu.cn/showproblem.php?pid=4302
- HDU Today&&http://acm.hdu.edu.cn/showproblem.php?pid=2112
- 找规律。。&&http://acm.hdu.edu.cn/showproblem.php?pid=1097
- 导弹拦截二&&http://acm.hdu.edu.cn/showproblem.php?pid=1257
- 最小路径覆盖&&http://acm.hdu.edu.cn/showproblem.php?pid=4160
- Max Sum &&http://acm.hdu.edu.cn/showproblem.php?pid=1003
- The 36th ACM/ICPC Asia Regional Beijing Site&&http://acm.hdu.edu.cn/showproblem.php?pid=4046
- 二分查找求函数的区间最小值&&http://acm.hdu.edu.cn/showproblem.php?pid=2899
- http://acm.hdu.edu.cn/showproblem.php?pid=1055&&Color a Tree
- A + B Problem II &&http://acm.hdu.edu.cn/showproblem.php?pid=1002
- Robberies&&http://acm.hdu.edu.cn/showproblem.php?pid=2955