时间限制 1000 ms 内存限制 65536 KB
题目描述
给出一句英文句子(只由大小写字母和空格组成,不含标点符号,也不会出现连续的空格),请将其中的所有单词顺序翻转
输入格式
多组数据,以EOF结束。
每行一句英文句子(确保只由大小写字母和空格组成,不含标点符号,也不会出现连续的空格,字符串总长度1000以内)
输出格式
每组数据输出一行,为反转后的字符串
代码:
#include<stdio.h>
#include<string>
#include<stack>
#include<iostream>
using namespace std;
int main(){
stack<string> s;
string ss;
while (cin>>ss){
s.push(ss);
if(cin.get() =='\n'){
while(true){
ss = s.top();
s.pop();
cout<<ss;
if(!s.empty())cout<<" ";
if(s.empty()) break;
}
cout<<endl;
}
}
return 0;
}