您的位置:首页 > 运维架构

[OpenJudge-NOI]List stl

2015-11-05 13:50 239 查看

代码

#include <cstdio>
#include <iostream>
#include <cstring>
#include <list>
#include <map>
using namespace std;

map<int,list<int> > m;

int n,x,y;
char op[10000];
int main(){
scanf("%d",&n);
while(n--){
scanf("%s",op);
if(strcmp(op,"new")==0){
scanf("%d",&x);
m.insert(map<int,list<int> >::value_type(x,list<int>()));
}
if(strcmp(op,"add")==0){
scanf("%d%d",&x,&y);
m[x].push_back(y);
}
if(strcmp(op,"merge")==0){
scanf("%d%d",&x,&y);
m[x].merge(m[y]);
//m[y].clear();
}
if(strcmp(op,"unique")==0){
scanf("%d",&x);
m[x].sort();
m[x].unique();
}
if(strcmp(op,"out")==0){
scanf("%d",&x);
m[x].sort();
list<int>::iterator it;
for(it=m[x].begin();it!=m[x].end();it++){
printf("%d ",*it);
}
printf("\n");
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: