您的位置:首页 > 产品设计 > UI/UE

Codeforces Beta Round #26 (Codeforces format) B Regular Bracket Sequence

2010-08-17 10:06 316 查看
问你,拿出若干个左括号或者右括号后,匹配的最大长度。。



我直接拿2704改的,数组开小了,悲剧了。。。今天改后AC了。。。



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int n;
int sta[1000005];
char str[1000005]; 
int stack(int x)
{
  sta[n++] = x;
}
int pop()
{
  int x;
  x = sta
;
  n--;
  return x;
}
int match(int m,int n)
{
  if(str[ sta[m] ] =='(' && str[ n ] == ')')
    return 1;
  return 0;
}
int main(void)
{
  int count = 0,i,len;
  while(scanf("%s",str) != EOF)
  {
    n = 0;
    memset(sta,'/0',sizeof(sta));
    count = 0;
    len = strlen(str);
    stack(0);
    for(i=1;i<len;i++)  
    {
      stack(i);
      if(n<2)
        continue;
      if( match(n-2,i) )
      {
        pop();      
        pop();
        count+=2;
      }
    }
    printf("%d/n",count);
  }
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: