题解
2026-05-30 13:50:49
发布于:重庆
12阅读
0回复
0点赞
没人发题解,我来发一个
#include<bits/stdc++.h>
using namespace std;
struct node{
string code;
int cnt;
};
bool cmp(node a,node b){
if (a.cnt != b.cnt){
return a.cnt > b.cnt;
}
return a.code < b.code;
}
int f(char c){
if ('0' <= c and c <= '9'){
return c - '0';
}
return c - 'A' + 10;
}
int g(string s){
return f(s[0]) * 16 + f(s[1]);
}
vector<node> v;
int n;
map<string, int> mp;
vector<string> vs;
string s;
int h(string s){
int ma = 2e9, k = 0;
for (int i = 0;i < 16;i ++){
int a = abs(g(v[i].code) - g(s));
if (a < ma){
ma = a;
k = i;
}
}
return k;
}
char p(int a){
if (a < 10){
return a + '0';
}
return a - 10 + 'A';
}
int main(){
cin >> n;
for (int i = 0;i < n;i ++){
cin >> s;
vs.push_back(s);
for (int j = 0;j < s.length() / 2; j ++){
mp[s.substr(j * 2, 2)]++;
}
}
for (auto a: mp){
v.push_back({a.first, a.second});
}
sort(v.begin(), v.end(), cmp);
for (auto a: v){
//cout << a.code << " " << a.cnt << endl;
}
for (int i = 0;i < 16;i ++){
cout << v[i].code;
}
cout << endl;
for (string s: vs){
for (int j = 0;j < s.length() / 2; j ++){
cout << p(h(s.substr(j * 2, 2)));
}
cout << endl;
}
return 0;
}
这里空空如也







有帮助,赞一个