浙江大学PAT上机题解析之1009. 说反话 (20)
生活随笔
收集整理的这篇文章主要介绍了
浙江大学PAT上机题解析之1009. 说反话 (20)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
1009. 说反话 (20)
时间限制 400 ms
内存限制 32000 kB
代码长度限制 8000 B
判题程序 Standard 作者 CHEN, Yue
给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。
输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。
输出格式:每个测试用例的输出占一行,输出倒序后的句子。
输入样例: Hello World Here I Come 输出样例: Come I Here World Hello#include<iostream> #include <stack> #include <string> using namespace std; int main() { bool flag=false; stack<string> s; string str; while(cin>>str) s.push(str); while(!s.empty()) { if (flag) cout<<" "; else flag=true; cout<<s.top(); s.pop(); } //system("pause"); return 0; }
#include<iostream> #include <stack> #include <string> using namespace std;int main() {bool flag=false;stack<string> s;string str;while(cin>>str)s.push(str);while(!s.empty()){if (flag)cout<<" ";elseflag=true;cout<<s.top();s.pop();}//system("pause");return 0; }
转载于:https://www.cnblogs.com/ainima/p/6331287.html
总结
以上是生活随笔为你收集整理的浙江大学PAT上机题解析之1009. 说反话 (20)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 《Effective Java》读书笔记
- 下一篇: Cocoa touch(十):UIDat