写一个程序完成以下命令:
new id ——新建一个指定编号为id的序列(id<10000)
add id num——向编号为id的序列加入整数num
merge id1 id2——合并序列id1和id2中的数,并将id2清空
unique id——去掉序列id中重复的元素
out id ——从小到大输出编号为id的序列中的元素,以空格隔开
16 new 1 new 2 add 1 1 add 1 2 add 1 3 add 2 1 add 2 2 add 2 3 add 2 4 out 1 out 2 merge 1 2 out 1 out 2 unique 1 out 1
1 2 3 1 2 3 4 1 1 2 2 3 3 4 1 2 3 4
#include<list> #include<stdio.h> using namespace std; const int N=10005; list<int>all[N]; int T,a,b,id,num;char s[N]; int main(){ for(scanf("%d",&T);T--;){ scanf("%s",s); switch(s[0]){ case ‘n‘:scanf("%*d");break; case ‘a‘:scanf("%d%d",&id,&num); all[id].push_back(num); all[id].sort(); break; case ‘o‘: scanf("%d",&id); for(int &x:all[id]) printf("%d ",x);puts(""); break; case ‘m‘:scanf("%d%d",&a,&b); all[a].merge(all[b]); all[id].sort(); break; case ‘u‘: scanf("%d",&id); all[id].unique(); break; } } return 0; }
asd
-------
原文:https://www.cnblogs.com/shenben/p/12757286.html