zoukankan      html  css  js  c++  java
  • 100722B

    在stack里套set,然后每次根据他的操作,在set里操作,把括号hash,插入,输出set的size-1

    #include<iostream>
    #include<set>
    #include<cstdio>
    #include<stack>
    #define ll long long
    #define st set<ll>
    using namespace std;
    stack<st>s;
    ll T,n,tot;
    char S[110];
    int main()
    {
        cin>>T;
        while(T--)
        {
            cin>>n;
            while(!s.empty())s.pop();
            for(int i=1;i<=n;i++)
            {
                scanf("%s",S);
                if(S[0]=='P')
                {
                    st x;x.clear();
                    x.insert(1);
                    s.push(x);
                    printf("%d
    ",0);
                }
                if(S[0]=='D')
                {
                    st a;a.clear();
                    a=s.top();
                    ll temp=a.size()-1;
                    s.push(a);
                    printf("%d
    ",temp);
                }
                if(S[0]=='U')
                {
                    st a=s.top();s.pop();
                    st b=s.top();s.pop();
                    for(st::iterator it=a.begin();it!=a.end();it++)
                        b.insert(*it);
                    s.push(b);
                    printf("%d
    ",b.size()-1);
                }
                if(S[0]=='I')
                {
                    st a=s.top();s.pop();
                    st b=s.top();s.pop();
                    st c;c.clear();
                    for(st::iterator it=a.begin();it!=a.end();it++)
                        if(b.count(*it))c.insert(*it);
                    s.push(c);
                    printf("%d
    ",c.size()-1); 
                }
                if(S[0]=='A')
                {
                    st a=s.top();s.pop();
                    st b=s.top();s.pop();
                    st c;c.clear();
                    ll sum=0;
                    for(st::iterator it=a.begin();it!=a.end();it++)
                        {sum*=171;sum+=*it;}
                    sum*=171;
                    b.insert(sum);
                    s.push(b);
                    printf("%d
    ",b.size()-1);
                }            
            }
            printf("***
    ");
        }
        return 0;
    }
  • 相关阅读:
    ny2 括号配对问题
    ny14 会场安排问题
    杭电ACM题目分类
    hdoj2037 今年暑假不AC
    ny37 回文字符串
    算法 字符串的排列组合
    手撸IoC
    Java设计模式
    多种方法求java求整数的位数
    二叉树之 二叉树深度
  • 原文地址:https://www.cnblogs.com/19992147orz/p/5995094.html
Copyright © 2011-2022 走看看