stack函数
头文件:#include<stack>
还要加上using namespace std;
empty() 堆栈为空则返回真
pop() 移除栈顶元素
push() 在栈顶增加元素
size() 返回栈中元素数目
top() 返回栈顶元素
Sample Input
3
olleh !dlrow
m’I morf .udh
I ekil .mca
Sample Output
hello world!
I’m from hdu.
I like acm.
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
int main()
{
stack<char> a;
char c;
int i,n;
cin>>n;
for(i=0;i<=n;i++){
while(c=getchar()!='\n'){
if(c==' '){
while(!a.empty()){
cout<<a.top();
a.pop();
}
cout<<' ';
}
else
a.push(c);
}
while(!a.empty()){
cout<<a.top();
a.pop();
}
cout<<endl;
}
return 0;
}