题解 [list方法]
2025-06-05 22:58:47
发布于:浙江
0阅读
0回复
0点赞
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
list<int> Node;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
Node.push_back(x);
}
while (m--) {
int a, b;
cin >> a >> b;
auto it = find(Node.begin(), Node.end(), a);
if (it != Node.end()) {
Node.insert(next(it), b);
}
}
bool first = true;
for (int num : Node) {
if (!first) cout << " ";
cout << num;
first = false;
}
return 0;
}
这里空空如也
有帮助,赞一个