括号序列noip模拟赛

来源:互联网 发布:淘宝网京东商城童装 编辑:程序博客网 时间:2024/05/22 10:35
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
char s[maxn];
int n,m,l=0,r=0;
int main(){
 scanf("%s",s+1);
 int n=strlen(s+1);
 for(int i=1;i<=n;i++){
  if(s[i]=='('){
   ++l;
  }
  if(s[i]==')'){
   if(l) --l;
   else ++r;
  }
 }
 cout<<r/2+r%2+l/2+l%2<<endl;
 return 0;
}
原创粉丝点击