7-32 说反话-加强版
题目链接-7-32 说反话-加强版
解题思路
STL stack
利用栈先进后出的性质,用istringstream
读入每个单词存到栈中,再依次输出栈的所有单词即可,
附上代码
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=1e5+5;
typedef long long ll;
typedef pair<int,int> PII;
string s,t;
stack<string> st;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
getline(cin,s);
istringstream in(s);
while(in>>t){
st.push(t);
}
while(!st.empty()){
cout<<st.top();
st.pop();
if(st.size()!=0)
cout<<" ";
}
return 0;
}