acm 1062反转问题
**#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
int main(){
//利用栈的思想解决这个问题,把每一个保存在栈中,然后遇到空格时就输出
int n;
char c;
cin>>n;
getchar();
while(n--){
stack<char> s;
while(true){
c=getchar();
if(c!=' '&&c!='\n'&&c!=EOF){
s.push(c);
}else {
while(!s.empty()){
cout<<s.top();
s.pop();
}
if(c=='\n'||c==EOF){
break;
}
cout<<" ";
}
}
cout<<endl;
}
return 0;
}**
分析:利用栈的思想解决这个问题,把每一个单词保存在栈中,然后遇到空格时就输出,然后继续保存继续输出,知道换行为止。