标签:hdu
题目Description
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=16891
Input
Output
Sample Input
((((B)()))()) (B)
Sample Output
4 1 题目分析: 题目优先类似线段的处理,从头扫面遇到‘(‘,盒子数加1,遇到‘)‘,盒子数减1,遇到‘B‘结束,输出结果即可。 AC代码:/** *@xiaoran *线段树 */ #include<iostream> #include<cstdio> #include<map> #include<cstring> #include<string> #include<algorithm> #include<queue> #include<vector> #include<stack> #include<cstdlib> #include<cctype> #include<cmath> using namespace std; int main() { string s; while(cin>>s){ int k=0,len=s.size(); for(int i=0;i<len;i++){ if(s[i]=='B') break; if(s[i]=='(') k++; if(s[i]==')') k--; } cout<<k<<endl; } return 0; }
标签:hdu
原文地址:http://blog.csdn.net/fool_ran/article/details/42423057