#include <iostream> #include <fstream> #include <string> #include <list> #include <map> using namespace std; int main(){ ifstream cin("D:\test\input.txt");//提交作业的时间,这一句删掉即可 int n,num1,num2; cin >> n; string s; map<int,list<int> > m1; //定义时注意右端>>有空格作为间隔,不然oj上会报错,但是vs2010没报错 while(n--){ cin >>s; switch(s[0]){ case 'n'://new cin >> num1; m1.insert(map<int, list<int>>::value_type(num1,list<int>()));//不进行强转回发生错误
break; case 'a'://add cin >> num1 >> num2; m1[num1].push_back(num2); break; case 'o'://out cin >> num1; for(list<int>::iterator i = m1[num1].begin();i!= m1[num1].end();i++){//因为是list所以没有<等 cout << *i<< " "; } cout << endl; break; case 'm'://merge cin>> num1 >> num2; m1[num1].merge(m1[num2]); break; case 'u'://unique cin >> num1; m1[num1].sort(); m1[num1].unique(); break; } } return 0; }