题解 | #点击消除#
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
#include <iostream>
#include <stack>
using namespace std;
int main() {
string str;
string str1 = "";
stack<char> temp;
cin >> str;
for (int i = 0; i < str.size(); i++) {
if (temp.empty() || temp.top() != str[i]) {
temp.push(str[i]);
} else {
temp.pop();
}
}
if (temp.empty())
cout << 0 << endl;
string res(temp.size(), '0');
for (int i = temp.size() - 1; i >= 0; i--) {
res[i] = temp.top();
temp.pop();
}
cout << res << endl;
}
查看21道真题和解析