stack的用法
#include <iostream>
#include <stack>
#include <map>
#include <set>
using namespace std;
const int MAXN = 2010;
const int N = 20;
int cnt;
stack<set<int> > stk;
map<set<int>, int> mp;
set<int> s1,s2;
void pop(){
s1 = stk.top(); stk.pop();
s2 = stk.top(); stk.pop();
}
void Push(){
set<int> s;
stk.push(s);
cout<<"0"<<endl;
}
void Dup(){
set<int> s;
s = stk.top(); stk.push(s);
cout<<(int)s.size()<<endl;
}
void Union(){
pop();
for (set<int>::iterator it = s1.begin(); it != s1.end(); it++) s2.insert(*it);
stk.push(s2);
cout<<(int)s2.size()<<endl;
}
void Intersect(){
pop();
set<int> s3;
for (set<int>::iterator it = s1.begin(); it != s1.end(); it++)
if (s2.find(*it) != s2.end()) s3.insert(*it);
stk.push(s3);
cout<<(int)s3.size()<<endl;
}
void Add(){
pop();
if (s1.empty()) s2.insert(0);
else {
if (!mp[s1]) mp[s1] = cnt++;
s2.insert(mp[s1]);
}
stk.push(s2);
cout<<s2.size()<<endl;
}
int main(){
int t,n;
char str[N];
cin>>t;
while (t--){
cin>>n;
while (!stk.empty())
stk.pop();
cnt = MAXN;
mp.clear();
while (n--){
cin>>str;
if (str[0] == 'P')
Push();
else if (str[0] == 'D')
Dup();
else if (str[0] == 'U')
Union();
else if (str[0] == 'I')
Intersect();
else Add();
}
cout<<"***"<<endl;
}
return 0;
}