XDOJ_1083_模拟
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了XDOJ_1083_模拟相关的知识,希望对你有一定的参考价值。
http://acm.xidian.edu.cn/problem.php?id=1083
栈,因为只有一种括号,所以只要模拟栈就可以了。
#include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; int main() { int T; string s; cin >> T; while(T--) { cin >> s; int len = s.length(),cnt = 0,ans = 0; for(int i = 0;i < len;i++) { if(s[i] == ‘(‘) cnt++; else if(cnt) { cnt--; ans += 2; } } cout << ans << endl; } return 0; }
以上是关于XDOJ_1083_模拟的主要内容,如果未能解决你的问题,请参考以下文章