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.

115 lines
2.2 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 + 10 - 'A') * 16;
else
res += (a - '0') * 16;
if (b >= 'A' && b <= 'F')
res += b + 10 - 'A';
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;
//struct Node {
// int id;
// int cnt;
// const bool operator<(const Node &b)const {
// if (cnt == b.cnt)
// return id < b.id;
// return cnt > b.cnt;
// }
//};
//Node<64>ٵ<EFBFBD><D9B5>ˣ<EFBFBD><CBA3>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>
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, c2;
c1 = s[j], c2 = s[j + 1];
int k = toDec(c1, c2);
b[k]++;
}
}
// ѡ<>ٿ<EFBFBD>ʼ~~~
// <20><><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ǻܶ<C7BA><DCB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>256<35><36>Ҳ<EFBFBD><D2B2><EFBFBD>ܸ<EFBFBD><DCB8>٣<EFBFBD><D9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD>֣<EFBFBD>
// <20><><EFBFBD><EFBFBD>Ҫѡ<D2AA><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>16<31><36><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>vec<node><3E><>
// vec<node><3E><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>о<EFBFBD><D0BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>for<6F><72>1<EFBFBD><31>mx<6D><78><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>mx<6D><78><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>mx_id<69><64><EFBFBD><EFBFBD>ֵ<EFBFBD>ı<EFBFBD><C4B1>ţ<EFBFBD>
//<2F><>һ<EFBFBD><D2BB>vec<int>!
//<2F><>ʼ<EFBFBD>ɣ<EFBFBD>
// for (int i = 0; i <= 255; i++)
// if (b[i])
// vec.push_back({i, b[i]});
//Ϊ<>˷<EFBFBD>ֹ<EFBFBD><D6B9>ɫ<EFBFBD><C9AB>ð<EFBFBD><EFBFBD><E4A3AC>ɸһ<C9B8>飬Ȼ<E9A3AC><C8BB>¼<EFBFBD><C2BC>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// sort(vec.begin(), vec.end());
//<2F>ɴ<EFBFBD><C9B4><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰʮ<C7B0><CAAE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for (int i = 0; i < 16; i++) {
int mx, mx_id;
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);
//important!!!
b[mx_id] = -1;
//<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>~<7E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
for (int i = 1; i <= 16; i++)
cout << toHex(vec[i]);
cout << endl;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><DAB6><EFBFBD>~
for (int i = 0; i < n; i++) {
for (int j = 0; j < q[0].size(); j += 2) {
char c1, c2;
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 < 16; k++) {
if (mi > abs(vec[k] - x)) {
mi = abs(vec[k] - x);
mi_p = k;
}
}
cout << toHex(mi_p)[1];
}
cout << endl;
}
return 0;
}