本文最后更新于 196 天前,其中的信息可能已经有所发展或是发生改变。
| 操作 | 功能 | 返回值 | 复杂度 |
|---|---|---|---|
| push() | 入栈 | 无 | O(1) |
| pop() | 出栈 | 无 | O(1) |
| top() | 取栈顶元素 | 元素值 | O(1) |
| empty() | 判断是否为空 | bool | O(1) |
| size() | 获取栈大小 | 整数 | O(1) |
| swap() | 交换两个栈 | 无 | O(1) |
输入样例:
olleh !dlrow
输出样例:
hello world!
#include<bits/stdc++.h>
using namespace std;
const int N = 1000010;
typedef long long LL;
typedef list<int>::iterator Iter;
list<int> L;
deque<int> dq;
queue<int> q;
stack<int> s;
vector<LL> a(N + 1, 0);
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
stack<char> ss;
while (1){
char ch = getchar();
if (ch == ' ' || ch == '\n' || ch == EOF) {
while (!ss.empty()) cout << ss.top(), ss.pop();
if (ch == '\n' || ch == EOF) break;
else cout << " ";
}
else ss.push(ch);
}
return 0;
}