大佬看看第一题有错吗 #include<iostream> (30316)#include<stack> #include<vector> (30320)#include<string> #include<algorithm> using namespace std; int main() { string s; cin >> s; stack<pair<char,int>> stk; int res = 0; for (int i = 0; i < s.size(); ++i) { if (stk.empty() || stk.top().first == '0' || s[i] == '1') { if (!stk.empty()) { res = max(res, i - stk.top().second - 1); } stk.push(pair<char,int>(s[i],i)); } else { stk.pop(); } } if (!stk.empty()) { res = max(res, int(s.size()) - stk.top().second - 1); } cout << s.size() - stk.size() << endl; return 0; }
点赞 评论

相关推荐

牛客网
牛客网在线编程
牛客网题解
牛客企业服务