#include #include #include #include #include using namespace std;

map<int, vector> idMap; // 保存每个id对应的序列 set idSet; // 保存已经存在的id

int main() { int n; cin >> n; while (n--) { string cmd; cin >> cmd; if (cmd == "new") { int id; cin >> id; idMap[id] = vector(); idSet.insert(id); } else if (cmd == "add") { int id, num; cin >> id >> num; idMap[id].push_back(num); } else if (cmd == "merge") { int id1, id2; cin >> id1 >> id2; idMap[id1].insert(idMap[id1].end(), idMap[id2].begin(), idMap[id2].end()); idMap[id2].clear(); idSet.erase(id2); } else if (cmd == "unique") { int id; cin >> id; vector &seq = idMap[id]; sort(seq.begin(), seq.end()); seq.erase(unique(seq.begin(), seq.end()), seq.end()); } else if (cmd == "out") { int id; cin >> id; vector &seq = idMap[id]; sort(seq.begin(), seq.end()); for (int x : seq) { cout << x << " "; } cout << endl; } } return 0;

Write a program to complete the following commandnew id - create a specified sequence of Numbers for id id 200000Add id num - to join the sequence of Numbers for id integer nummerge id1 id2 - merger

原文地址: https://www.cveoy.top/t/topic/gwnG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录