HDU - 5479 Scaena Felix (栈模拟)水
2016-04-07 22:13
453 查看
HDU - 5479 Scaena Felix
Description Given a parentheses sequence consist of '(' and ')', a modify can filp a parentheses, changing '(' to ')' or ')' to '('. If we want every not empty <b>substring</b> of this parentheses sequence not to be "paren-matching", how many times at least to modify this parentheses sequence? For example, "()","(())","()()" are "paren-matching" strings, but "((", ")(", "((()" are not. Input The first line of the input is a integer , meaning that there are test cases. Every test cases contains a parentheses sequence only consists of '(' and ')'. . Output For every test case output the least number of modification. Sample Input 3 () (((( (()) Sample Output 1 0 2 Source BestCoder Round #57 (div.2) //题意: 给你一串字符串,问有几对括号 直接栈模拟就行了 #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<cmath> #include<map> #include<queue> #include<stack> #define INF 0x3f3f3f3f #define ull unsigned lonb long #define ll long long #define IN __int64 #define N 1010 #define M 1000000007 using namespace std; stack<char>ss; char s ; int main() { int t,i,j; scanf("%d",&t); while(t--) { scanf("%s",s); int len=strlen(s); int l=0,r=0; for(i=0;i<len;i++) { if(s[i]=='(') { l++; ss.push(s[i]); } else { if(l) { r++;l--; ss.pop(); } } } printf("%d\n",r); } return 0; } |
相关文章推荐
- jQuery选择器
- error:[WinError 2] 系统找不到指定文件
- Hive 各版本关键新特性(Key New Feature)介绍
- HTML
- 习题相关的笔记JS(一)
- h5 range应用 透明度+RGB
- JS实现的网页上的颜色拾色器
- example_Jquery Ajax + php 三级联动
- 哎呀,JSP小记_第一目
- SharedPreferences 与Editor
- HTML基础(四)
- 7个你可能不认识的CSS单位:rem vh vw vmin vmax ex ch
- jquery 实现导航栏滑动效果
- 深入理解Javascript之执行上下文(Execution Context)
- zepto.1.1.6.js源码中的each方法学习笔记
- 【BZOJ 1016】【JSOI 2008】最小生成树计数
- 在Dynamic Web Project中新建jsp报错
- Jquery判断数组中是否包含某个元素$.inArray()的用法
- JS Ajax实现文件上传
- EL JSTL