求调60
查看原帖
求调60
186546
lwyznoip楼主2024/6/23 21:03
#include <bits/stdc++.h>
using namespace std;

int s1[20][20];
int s2[20][20];
int a[256];
int b[16];

int hsix(char x) {

    if (x >= '0' && x <= '9') return x - '0';
    if (x == 'A') return 10;
    if (x == 'B') return 11;
    if (x == 'C') return 12;
    if (x == 'D') return 13;
    if (x == 'E') return 14;
    if (x == 'F') return 15;

}

char hten(int x) {

    if (x >= 0 && x <= 9) return (char)(x + '0');
    if (x == 10) return 'A';
    if (x == 11) return 'B';
    if (x == 12) return 'C';
    if (x == 13) return 'D';
    if (x == 14) return 'E';
    if (x == 15) return 'F';

}

int chzh(int c) {

    int f = 256, r = -1;

    for (int i = 0; i < 16; i++) {

        int d = c - b[i];

        d = abs (d);

        if (d < f) {

            f = d;

            r = i;

        }

    }

    return r;

}

int main() {

    int n, m;

    cin >> n;

    for (int i = 0; i < 256; i++)

        a[i] = -1;

    for (int i = 0; i < n; i++) {

        string s;

        cin >> s;

        m = s.size() / 2;

        for (int j = 0; j < m; j++) {

            int c = hsix(s[j * 2]) * 16 + hsix(s[j * 2 + 1]);

            s1[i][j] = c;

            a[c]++;

        }

    }

    for (int c = 0; c < 16; c++) {

        int max = 0, id = -1;

        for (int i = 0; i < 256; i++)

            if (a[i] > max) {

                max = a[i];

                id = i;

            }

        b[c] = id;

        a[id] = -1;

    }


    for (int i = 0; i < n; i++)

        for (int j = 0; j < m; j++)

            s2[i][j] = chzh(s1[i][j]);

    for (int c = 0; c < 16; c++)

        cout << hten(b[c] / 16) << hten(b[c] % 16);

    cout << endl;

    for (int i = 0; i < n; i++) {

        for (int j = 0; j < m; j++)

            cout << hten(s2[i][j]);

        cout << endl;

    }

    return 0;

}
2024/6/23 21:03
加载中...