这是一道阅读理解题...说实话真的没看懂题,不知道为什么第二个样例不能看0 看1 写0 写1,这样不也是20吗??但是直觉告诉我这个和括号配对差不多,然后照着样例瞎敲了份code就过了...代码的思路就是和括号配对一样,遇到两个相邻的就pop出去,否则就push进来,栈中剩下的都是配不了对的,所以除以2乘5就是得分。如果有理解题意的麻烦给我讲一下....
#include <bits/stdc++.h> using namespace std; int main() { string str; cin>>str; int len = str.length(); stack<char> s; int ans = 0; for(int i=0;i<len;i++){ if(s.empty()){ s.push(str[i]); continue; } if(s.top() == str[i]) { ans += 10; s.pop(); } else { s.push(str[i]); } } ans += s.size() / 2 * 5; printf("%d\n", ans); return 0; }