the Zeros and Ones

来源:互联网 发布:阿里云搭建ftp 编辑:程序博客网 时间:2024/05/18 13:05
#include<iostream>#include<string>#include<stack>using namespace std;int main(){int n, x, ans = 0;string str;stack<int> st;cin >> n >> str;for(int i = 0; i < n; ++i){x = str[i] - '0';if(st.empty()) st.push(x);else if(st.top() != x) st.pop(), ans += 2;else st.push(x);}cout << n-ans <<endl;return 0;}

0 0
原创粉丝点击