AcWing 3678. 模拟出入栈游戏
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
int t, n, m, k, l, r, op, x, y;
string tmp, str;
int siz = 26;
void solve() {
for (int i = 0; i < siz; i++) {
tmp.push_back('a' + i);
}
while (cin >> str) {
x = y = 0;
stack<char> stk;
while (true) {
while (!stk.empty() && stk.top() == str[y]) {
stk.pop();
y++;
}
if (x == siz)break;
stk.push(tmp[x]);
x++;
}
cout << (stk.empty() ? "yes" : "no") << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}