#include <bits/stdc++.h>
using namespace std;
const int mod = 2333;
int t,n,x,flag;
vector <int> link[mod + 2];
int main(){
cin >> t;
while (t--){
cin >> n;
for (int i = 0 ; i < mod ; i++) link[i].clear();
for (int i = 1 ; i <= n ; i++){
cin >> x;
flag = 1;
for (int j = 0 ; j < link[x % mod].size() ; j++){
if (link[x % mod][j] == x){
flag = 0;
break;
}
}
if (flag){
cout << x << ' ';
link[x % mod].push_back(x);
}
}
puts("");
}
return 0;
}
这份代码无法通过编译。
#include <iostream>
#include <vector>
using namespace std;
const int mod = 2333;
int t,n,x,flag;
vector <int> link[mod + 5];
int main(){
cin >> t;
while (t--){
cin >> n;
for (int i = 0 ; i < mod ; i++) link[i].clear();
for (int i = 1 ; i <= n ; i++){
cin >> x;
flag = 1;
for (int j = 0 ; j < link[x % mod].size() ; j++){
if (link[x % mod][j] == x){
flag = 0;
break;
}
}
if (flag){
cout << x << ' ';
link[x % mod].push_back(x);
}
}
puts("");
}
return 0;
}
这份代码可以通过编译。
万能头不能用了吗?