
#include <iostream>
#include <list>
#include <string>
#include <stdio.h>
using namespace std;
int main()
{
int n, x1, x2;
list<int> a[10001]; //用list定义数组,好神奇
cin >> n;
while (n--)
{
string st;
cin >> st;
if (st == "new") //这里不就相当于什么都没干,提前开好了已经
{
cin >> x1;
}
else if (st == "add")
{
cin >> x1 >> x2;
a[x1].push_back(x2);
}
else if (st == "merge")
{
cin >> x1 >> x2;
a[x1].merge(a[x2]); //在这里wa了好几次,我给他加上了清空函数,结果对,但是wa了
}
else if (st == "unique") //这里记得要先排序
{
cin >> x1;
a[x1].sort();
a[x1].unique();
}
else if (st == "out")
{
cin >> x1;
a[x1].sort();
list<int>::iterator i;
for (i = a[x1].begin(); i != a[x1].end(); i++)
{
cout << *i << " ";
}
cout << endl;
}
}
return 0;
}
List
非常适合合并 merge
操作List
竟然害提供了 unique
方法???