关于万能头
查看原帖
关于万能头
1334925
The_foolishest_OIer楼主2024/8/31 12:49
#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;
}

这份代码可以通过编译。

万能头不能用了吗?

2024/8/31 12:49
加载中...