题解 | 点击消除
点击消除
https://www.nowcoder.com/practice/8d3643ec29654cf8908b5cf3a0479fd5
#include <iostream>
#include<stack>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
stack<char>sta;
string t;
cin>>t;
for(char i:t){
if(!sta.empty()){
if(sta.top()!=i)sta.push(i);
else sta.pop();
}
else sta.push(i);
}
vector<char>res;
if(sta.empty())cout<<0<<endl;
else {
while(!sta.empty()){
res.push_back(sta.top());
sta.pop();
}
}
reverse(res.begin(),res.end());
for(char i:res){
cout<<i;
}
return 0;
}
查看10道真题和解析