/*
中兴第二题:优先听汇报
描述:不同部落进行汇报,首领先按给定的顺序听重要的部落的汇报,剩下的部落按编号升序听汇报。
输入:
p(汇报的总数) q(重点关注的部落数)
数(汇报的部落,一个部落可能有多个汇报)
数组(需要重点关注并排好序的部落编号)
例子:
输入:
5 3
5 4 3 2 1
3 5 4
输出:
3 5 4 1 2
输入:
11 6
2 3 1 3 2 4 6 7 9 2 19
2 1 4 3 9 6
输出:
2 2 2 1 4 3 3 9 6 7 19
*/
//以下代码为ChatGPT生成
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
int main() {
int p, q; //汇报数p 重要部落数q
std::cin >> p >> q;
std::vector<int> reports(p); //所有汇报
std::map<int, std::vector<int>> tribalReports; //重要部落及对应的汇报
std::vector<int> attentionTribes(q); //重要部落
//输入汇报
for (int i = 0; i < p; ++i) {
std::cin >> reports[i];
}
//输入重要部落
for (int i = 0; i < q; ++i) {
std::cin >> attentionTribes[i];
tribalReports[attentionTribes[i]] = std::vector<int>(); //初始化重要部落的汇报
}
//遍历汇报
for (int report : reports) {
//如果是重要的汇报,则存储到tribalReports
if (tribalReports.find(report) != tribalReports.end()) {
tribalReports[report].push_back(report);
}
}
//先输出重点汇报
for (int attentionTribe : attentionTribes) {
for (int report : tribalReports[attentionTribe]) {
std::cout << report << " ";
}
}
//剩余汇报
std::vector<int> remainingReports;
//遍历汇报
for (int report : reports) {
//如果不是重要的汇报,则存储到remainingReports
if (tribalReports.find(report) == tribalReports.end()) {
remainingReports.push_back(report);
}
}
//排序并输出剩余汇报
std::sort(remainingReports.begin(), remainingReports.end());
for (int report : remainingReports) {
std::cout << report << " ";
}
return 0;
}