You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
1.5 KiB

11 months ago
#include <bits/stdc++.h>
using namespace std;
const int N = 256;
int b[N];
int toDec(char a, char b) {
int res = 0;
if (a >= 'A' && a <= 'F')
res += (a - 'A' + 10) * 16;
else
res += (a - '0') * 16;
if (b >= 'A' && b <= 'F')
res += b - 'A' + 10;
else
res += b - '0' ;
return res;
}
string toHex(int x) {
int a = x % 16;
int b = x / 16;
char c1, c2;
if (a >= 10)
c1 = 'A' + a - 10;
else
c1 = a + '0';
if (b >= 10)
c2 = 'A' + b - 10;
else
c2 = b + '0';
string res;
res.push_back(c2);
res.push_back(c1);
return res;
}
vector<string>q;
vector<int>vec;
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
string s;
cin >> s;
q.push_back(s);
for (int j = 0; j < s.size(); j += 2) {
char c1 = s[j], c2 = s[j + 1];
int k = toDec(c1, c2);
b[k]++;
}
}
for (int i = 0; i < 16; i++) {
int mx = 0, mx_id = -1;
for (int j = 0; j < 256; j++)
if (b[j] > mx) {
mx = b[j];
mx_id = j;
}
vec.push_back(mx_id);
b[mx_id] = -1;
}
for (int i = 0; i < min(16, (int)vec.size()); i++)
cout << toHex(vec[i]) ;
cout << endl;
for (int i = 0; i < n; i++) {
for (int j = 0; j < q[0].size(); j += 2) {
int c1 = q[i][j], c2 = q[i][j + 1];
int x = toDec(c1, c2);
int mi = INT_MAX;
int mi_p = 0;
for (int k = 0; k < min(16, (int)vec.size()); k++) {
if (mi > abs(vec[k] - x)) {
mi = abs(vec[k] - x);
mi_p = k;
}
}
cout << toHex(mi_p)[1];
}
cout << endl;
}
return 0;
}