UESTC 1823 In Galgame We Trust 模拟

简介:

今天比赛时一直没写出来的一道水题,题目很简单,比赛的时候心态不对,一直没写对

其实就是栈进行括号匹配再加一个数组记录层次即可

/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
stack<char> st;
int ans[1000005],now;
int Max;
int main()
{
    int T,C=0;
    scanf("%d",&T);
    getchar();
    while(T--)
    {
        Max=now=0;
        char s,aim;
        ans[now]=0;
        while(!st.empty())st.pop();
        while(1)
        {
            s=getchar();
            if(s=='\n') break;
            if(s=='{'||s=='['||s=='(')
            {
                if(s=='(')s++;
                else s+=2;
                st.push(s);
                ans[++now]=0;
            }
            else
            {
                if(st.empty())
                {
                    now=0;
                    ans[now]=0;
                }
                else if(s==st.top())
                {
                    st.pop();
                    ans[now]+=2;
                    ans[now-1]+=ans[now];
                    now--;
                    Max=max(Max,ans[now]);
                }
                else
                {
                    while(!st.empty())st.pop();
                    now=0;
                    ans[now]=0;
                }
            }
        }
        printf("Case #%d: ",++C);
        if(Max)printf("%d\n",Max);
        else puts("I think H is wrong!");
    }
}


目录
相关文章
Mac Source Tree拉代码报错,remote: CODING 提示: Authentication failed. remote: 认证失败,请确认您输入了正确的账号密码。 fatal...
Mac Source Tree拉代码报错,remote: CODING 提示: Authentication failed. remote: 认证失败,请确认您输入了正确的账号密码。 fatal...
1696 0
Mac Source Tree拉代码报错,remote: CODING 提示: Authentication failed. remote: 认证失败,请确认您输入了正确的账号密码。 fatal...
|
8月前
|
Web App开发 安全 网络安全
关于 Chrome 开发者工具 Network 面板里观察到的 net ERR_CERT_AUTHORITY_INVALID 错误
关于 Chrome 开发者工具 Network 面板里观察到的 net ERR_CERT_AUTHORITY_INVALID 错误
|
23天前
|
芯片
芯片验证 | UVM的domain机制
芯片验证 | UVM的domain机制
15 0
|
10月前
|
iOS开发
iOS 逆向编程(Error)ssh_exchange_identification: read: Connection reset by peer
iOS 逆向编程(Error)ssh_exchange_identification: read: Connection reset by peer
111 0
|
11月前
|
Kubernetes 安全 Cloud Native
基于 Network Policy 限制服务交互
安全,无论是基于传统的单体服务模型还是当下流行的云原生微服务模型,其自始至终是一个关注度较高的话题。诚然,安全性是一个广泛的概念,但本文更多地将聚焦在微服务架构体系,深入到一个至为关键的层面,即“服务间的交互安全“。
44 0
|
网络协议 网络架构
eve-ng模拟ospf虚连接小实验
eve-ng模拟ospf虚连接小实验
206 0
eve-ng模拟ospf虚连接小实验
|
数据安全/隐私保护
研究fabric-sample的balance-transfer例子(1注册用户)
研究fabric-sample的balance-transfer例子(1注册用户)
1572 0
|
机器学习/深度学习 数据库 数据安全/隐私保护