UVALive
来源:互联网 发布:手机怎么避开网络监控 编辑:程序博客网 时间:2024/05/18 02:54
用栈消去已经完美的括号,剩下的分两种情况处理就是了
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <algorithm>#include <cmath>#include <queue>#include <vector>#include <set>#include <stack>#include <map>#include <climits>using namespace std;typedef long long ll;const int maxn = 100 + 7, INF = 0x3f3f3f3f, mod = 1e9 + 7;stack<char> sk;char s[maxn];int n;int main() { int T; scanf("%d", &T); while(T--) { scanf("%d%s", &n, s); for(int i = 0; i < n; ++i) { if(!sk.empty()) { if(s[i] == ')') { if(sk.top() == '(') sk.pop(); else sk.push(s[i]); } else sk.push(s[i]); } else sk.push(s[i]); } int ans = 0; while(!sk.empty()) { char c1 = sk.top(), c2; sk.pop(); if(!sk.empty()) c2 = sk.top(), sk.pop(); if(c1 == c2) ans ++; else ans += 2; //cout << ans << " == " << endl; } cout << ans << endl; } return 0;}
阅读全文
1 0
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- 就是接地气!"互联网刷新未来"创新创业峰会等你来!【火热抢票中】
- 58集团品牌升级 定义生活服务新生态
- FLYPRO飞豹携XEagle无人机 亮相2016全球最大无人机展AUVSI XPONENTIAL
- 细菌也能制造量子点,敢情又要换电视了?
- 把最美献给母亲节 OPPO R9记录世界微笑日
- UVALive
- Thread
- [剑指offer]算法7 斐波那契数列
- android studio3.0使用报错解决
- 常用的机器学习算法学习
- freemarker模板引擎
- 移动开发调试模式
- 链表 二叉树
- 继下架全部医院广告之后 360搜索发布首份医疗机构白名单