40(list)

 1 #include <iostream>
 2 #include <list>
 3 #include <string>
 4 #include <cstdio>
 5 using namespace std;
 6 const int N = 10001;
 7 
 8 int main()
 9 {    
10     int n,id,num; 
11     scanf("%d",&n);
12     list<int> lst[N];
13     string order;
14     while(n --){
15         cin >> order;
16         if(order == "new"){
17             scanf("%d",&id);
18         }
19         else if(order == "add"){
20             scanf("%d%d",&id,&num);
21             lst[id].push_back(num);
22         }
23         else if(order == "merge"){
24             int id2;
25             scanf("%d%d",&id,&id2);
26             lst[id].merge(lst[id2]);
27         }
28         else if(order == "unique"){
29             scanf("%d",&id);
30             lst[id].sort(greater<int>()); 
31             lst[id].unique();//删除连续出现的重复元素,所以最好先排序 
32         }
33         else{
34             scanf("%d",&id);
35             lst[id].sort();
36             for (list<int>::iterator it = lst[id].begin(); it != lst[id].end(); it++)
37                 cout << *it << " ";
38             cout << endl;
39         }
40     }
41     return 0;
42 }

 

posted @ 2022-11-23 20:26  balabalahhh  阅读(54)  评论(0编辑  收藏  举报