题目链接
B. YetnotherrokenKeoard
题意
输入
输出
思路
用两个栈分别维护小写字母下标和大写字母下标,用一个vis
数组标记字母是否删除
示例代码
void solve() {string s;cin >> s;int n = s.size();vector<bool> vis(n, false);stack<int>sk1, sk2;fer(i, 0, n){if(s[i] >= 'a' && s[i] <= 'z' && s[i] != 'b') sk1.push(i);else if(s[i] >= 'A' && s[i] <= 'Z' && s[i] != 'B') sk2.push(i);if(s[i] == 'b'){vis[i] = true;if(!sk1.empty()) vis[sk1.top()] = true, sk1.pop();}else if(s[i] == 'B'){vis[i] = true;if(!sk2.empty()) vis[sk2.top()] = true, sk2.pop();}}fer(i, 0, n){if(!vis[i]) cout << s[i];}cout << '\n';
}