'commit'
This commit is contained in:
83
GESP/Level4/GESP202306/manfen.cpp
Normal file
83
GESP/Level4/GESP202306/manfen.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 300;
|
||||
int b[N];
|
||||
vector<int> top16;
|
||||
int toDec(string s) {
|
||||
int sum = 0;
|
||||
if (s[0] >= 'A' && s[0] <= 'F')
|
||||
sum = (s[0] - 'A' + 10) * 16;
|
||||
else
|
||||
sum = (s[0] - '0') * 16;
|
||||
if (s[1] >= 'A' && s[1] <= 'F')
|
||||
sum += (s[1] - 'A' + 10);
|
||||
else
|
||||
sum += (s[1] - '0');
|
||||
return sum;
|
||||
}
|
||||
string toHex(int x){
|
||||
string res;
|
||||
while(x){
|
||||
int t = x % 16;
|
||||
if(t>=10)
|
||||
res+=t-10+'A';
|
||||
else res+=t+'0';
|
||||
x/=16;
|
||||
}
|
||||
reverse(res.begin(),res.end());
|
||||
return res;
|
||||
}
|
||||
char find(int q){
|
||||
int mi = INT_MAX, mp = 0;
|
||||
for (int i = 0; i < top16.size();i++){
|
||||
if(abs(q-top16[i])<mi){
|
||||
mi = abs(q-top16[i]);
|
||||
mp = i;
|
||||
}
|
||||
}
|
||||
if(mp>=10)
|
||||
return (char)(mp - 10 + 'A');
|
||||
return (char)(mp + '0');
|
||||
}
|
||||
string c[N];
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
cin>>n;
|
||||
for (int i = 1;i<=n;i++){
|
||||
string s;
|
||||
cin >> s;
|
||||
c[i] = s;
|
||||
for (int j = 0; j < s.size();j+=2){
|
||||
string x;
|
||||
x.push_back(s[j]);
|
||||
x.push_back(s[j + 1]);
|
||||
b[toDec(x)]++;
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= 16;i++){
|
||||
int mx = 0, mp = 0;
|
||||
for (int j = 0; j < 256;j++)
|
||||
if(b[j]>mx){
|
||||
mx = b[j];
|
||||
mp = j;
|
||||
}
|
||||
b[mp] = 0;
|
||||
top16.push_back(mp);
|
||||
}
|
||||
for (int i = 0; i < top16.size();i++)
|
||||
cout << toHex(top16[i]);
|
||||
cout << endl;
|
||||
for (int i = 1; i <= n;i++){
|
||||
string s = c[i];
|
||||
for (int j = 0; j < s.size();j+=2){
|
||||
string x;
|
||||
x.push_back(s[j]);
|
||||
x.push_back(s[j + 1]);
|
||||
int q=toDec(x);
|
||||
cout<<find(q);
|
||||
}
|
||||
cout<<endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user