标签:har class ack style print begin using nbsp for
在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\n",0); } if(S[0]==‘D‘) { st a;a.clear(); a=s.top(); ll temp=a.size()-1; s.push(a); printf("%d\n",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\n",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\n",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\n",b.size()-1); } } printf("***\n"); } return 0; }
标签:har class ack style print begin using nbsp for
原文地址:http://www.cnblogs.com/19992147orz/p/5995094.html