67 lines
1.7 KiB
C++
67 lines
1.7 KiB
C++
|
|
#include <bits/stdc++.h>
|
|||
|
|
using namespace std;
|
|||
|
|
|
|||
|
|
const int N = 256;
|
|||
|
|
int b[N]; // 桶
|
|||
|
|
int a[17], al;
|
|||
|
|
|
|||
|
|
string c[N];
|
|||
|
|
int cl;
|
|||
|
|
int get(char x) {
|
|||
|
|
if (x >= '0' && x <= '9')
|
|||
|
|
return x - '0';
|
|||
|
|
return x - 'A' + 10;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
int toDec(char a, char b) { return get(a) * 16 + get(b); }
|
|||
|
|
int main() {
|
|||
|
|
int n;
|
|||
|
|
cin >> n;
|
|||
|
|
for (int i = 1; i <= n; i++) {
|
|||
|
|
string s;
|
|||
|
|
cin >> s;
|
|||
|
|
c[++cl] = s; // 原始数组保存下来
|
|||
|
|
// 字符串长度 s.size()
|
|||
|
|
for (int j = 0; j < s.size(); j += 2) {
|
|||
|
|
int idx = toDec(s[j], s[j + 1]); // 对应的十进制数值
|
|||
|
|
b[idx]++; // 维护桶
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 猴子选大王共16次
|
|||
|
|
for (int i = 1; i <= 16; i++) {
|
|||
|
|
int mx = -1, mp = 0;
|
|||
|
|
for (int j = 0; j < N; j++) {
|
|||
|
|
if (b[j] > mx) {
|
|||
|
|
mx = b[j];
|
|||
|
|
mp = j;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
a[++al] = mp; // 本轮次找到的大王位置是mp,记录下来到a数组中去
|
|||
|
|
b[mp] = -1; // 避免重复选,把大王出列
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 遍历原始数组
|
|||
|
|
for (int i = 1; i <= n; i++) {
|
|||
|
|
for (int j = 0; j < c[i].size(); j += 2) {
|
|||
|
|
int old = toDec(c[i][j], c[i][j + 1]);
|
|||
|
|
// 需要与b数组中的每一个数值进行对比,看看与哪个数值的绝对值差最小,也就是与谁最接近`
|
|||
|
|
int mi = INT_MAX,
|
|||
|
|
mp = 0; // mi最小的差绝对值,mp就是最小差绝对值所在的位置号
|
|||
|
|
for (int k = 1; k <= 16; k++) {
|
|||
|
|
int x = b[k];
|
|||
|
|
int d = abs(x - old);
|
|||
|
|
if (d < mi) {
|
|||
|
|
mp = k;
|
|||
|
|
mi = d;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
if (mp >= 10)
|
|||
|
|
cout << mp - 10 + 'A';
|
|||
|
|
else
|
|||
|
|
cout << mp;
|
|||
|
|
}
|
|||
|
|
cout << endl;
|
|||
|
|
}
|
|||
|
|
return 0;
|
|||
|
|
}
|