码迷,mamicode.com
首页 > 其他好文 > 详细

UESTC 10 In Galgame We Trust

时间:2015-04-20 14:30:51      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn= 1000010;
char s[maxn];
char stack[maxn];
int sta[maxn];
int flag[maxn];
int main()
{
    int sb;
    int uu;
    scanf("%d", &sb);
    for (uu = 1; uu <= sb; uu++)
    {
        scanf("%s", s);
        int i;
        int b = -1;//栈底
        int y = strlen(s);
        memset(flag, 0, sizeof(flag));
        for (i = 0; i < y; i++)
        {
            if (b == -1)
            {
                b++;
                stack[b] = s[i];
                sta[b] = i;
            }
            else
            {
                if (s[i] == { || s[i] == ( || s[i] == [)
                {
                    b++;
                    stack[b] = s[i];
                    sta[b] = i;
                }
                else if (s[i] == ))
                {
                    if (stack[b] == ()
                    {

                        flag[i] = 1;
                        flag[sta[b]] = 1;
                        b--;
                    }
                    else
                    {
                        b++;
                        stack[b] = s[i];
                        sta[b] = i;
                    }
                }
                else if (s[i] == ])
                {
                    if (stack[b] == [)
                    {
                        flag[i] = 1;
                        flag[sta[b]] = 1;
                        b--;

                    }
                    else
                    {
                        b++;
                        stack[b] = s[i];
                        sta[b] = i;
                    }
                }
                else if (s[i] == })
                {
                    if (stack[b] == {)
                    {
                        flag[i] = 1;
                        flag[sta[b]] = 1;
                        b--;

                    }
                    else
                    {
                        b++;
                        stack[b] = s[i];
                        sta[b] = i;
                    }
                }
            }
        }
        int sum = 0;
        int ans = 0;
        for (i = 0; i <= y; i++)
        {
            if (flag[i] == 1) sum++;
            else
            {
                if (sum > ans) ans = sum;
                sum = 0;
            }
        }
        printf("Case #%d: ", uu);
        if(ans!=0) printf("%d\n", ans);
        else printf("I think H is wrong!\n");
    }
    return 0;
}

 

UESTC 10 In Galgame We Trust

标签:

原文地址:http://www.cnblogs.com/zufezzt/p/4441283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!