讨论/《美团 2021 届秋季校园招聘笔试真题》 - 小团的选调计划/
《美团 2021 届秋季校园招聘笔试真题》 - 小团的选调计划
共 3 个回复
#include <iostream>
#include <unordered_map>

using namespace std;

const int N = 310;

int n, a[N][N];
int res[N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++)
            cin >> a[i][j];
    
    unordered_map<int, int> hash;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) {
            int x = a[i][j];
            if (!hash.count(x)) {
                hash[x] = i;
                res[i] = x;
                break;
            }
        }

    for (int i = 1; i <= n; i++) cout << res[i] << " ";
    cout << endl;

    return 0;
}
import java.io.*;
import java.util.*;

class Solution {
    static final int N = 310;

    static int[][] a = new int[N][N];
    static int[] res = new int[N];

    public static void main(String[] args) throws IOException {
        var reader = new BufferedReader(new InputStreamReader(System.in));
        var writer = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(reader.readLine());
        for (int i = 1; i <= n; i++) {
            var strings = reader.readLine().split(" ");
            for (int j = 1; j <= n; j++) a[i][j] = Integer.parseInt(strings[j - 1]);
        }

        Map<Integer, Integer> hash = new HashMap<>();
        for (int i = 1; i <= n; i++)
            for (int j = 1; j <= n; j++) {
                int x = a[i][j];
                if (!hash.containsKey(x)) {
                    hash.put(x, i);
                    res[i] = x;
                    break;
                }
            }

        for (int i = 1; i <= n; i++) writer.write(res[i] + " ");
        writer.write("\n");

        writer.flush();
        reader.close();
        writer.close();
    }
}
1
import java.util.*;
import java.io.*;

public class Solution {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        Set<Integer> set = new HashSet<>();
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            String[] arr = reader.readLine().split(" ");
            for (int j = 0; j < n; j++) {
                int id = Integer.parseInt(arr[j]);
                if (!set.contains(id)) {
                    ans[i] = id;
                    set.add(id);
                    break;
                }
            }
        }
        for (int i = 0; i < n; i++) {
            System.out.print(ans[i]);
            if (i != n - 1) {
                System.out.print(" ");
            }
        }
    }
}
#include<iostream>
#include<unordered_set>
#include<vector>
using namespace std;

int main(){
    int x;
    cin>>x;
    vector<vector<int>> vv;
    int p=x;
    while(p--){
        vector<int> v;
        int q=x;
        while(q--){
            int ii;
            cin>>ii;
            v.push_back(ii);
        }
        vv.push_back(v);
    }
    unordered_set<int> se;

    for(int i=0;i<x;i++){
        for(int j=0;j<x;j++){
            if(se.find(vv[i][j])==se.end()){
                se.insert(vv[i][j]);
                cout<<vv[i][j]<<" ";
                break;
            }
        }
    }



}