请用C++语言重新编写
时间: 2023-10-09 17:10:16 浏览: 37
好的,以下是使用 C++ 语言重新编写的代码:
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void update_chat_list(vector<int>& chat_list, int friend_id) {
if (find(chat_list.begin(), chat_list.end(), friend_id) != chat_list.end()) {
chat_list.erase(find(chat_list.begin(), chat_list.end(), friend_id));
}
chat_list.insert(chat_list.begin(), friend_id);
}
void process_communication() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
vector<int> friend_ids(t);
for (int j = 0; j < t; j++) {
cin >> friend_ids[j];
}
vector<int> chat_list;
for (int j = 0; j < t; j++) {
update_chat_list(chat_list, friend_ids[j]);
}
for (int j = 0; j < chat_list.size(); j++) {
cout << chat_list[j];
if (j != chat_list.size()-1) {
cout << " ";
}
}
cout << endl;
}
}
int main() {
process_communication();
return 0;
}
```
这个代码与之前的 Python 代码基本相同,只是使用了 C++ 的容器 vector 代替了 Python 的列表,以及使用了 C++ 的输入输出函数。
如果你还有其他问题,可以随时问我。