'commit'
This commit is contained in:
47
GESP/Level4/GESP202306/4_1.cpp
Normal file
47
GESP/Level4/GESP202306/4_1.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
typedef long long LL;
|
||||
const int N = 110;
|
||||
int a[N], al;
|
||||
// 变换
|
||||
int change(int y) {
|
||||
y *= 7;
|
||||
while (y > 9)
|
||||
y = y / 10 + y % 10;
|
||||
return y;
|
||||
}
|
||||
|
||||
// 检查x是不是幸运数
|
||||
bool check(LL x) {
|
||||
int idx = 0;
|
||||
while (x) {
|
||||
idx++;
|
||||
int y = x % 10;
|
||||
x /= 10;
|
||||
if (idx % 2 == 1) // 奇数位
|
||||
y = change(y);
|
||||
// 偶数位不变
|
||||
a[++al] = y;
|
||||
}
|
||||
LL q = 0;
|
||||
|
||||
// 反着拼回来
|
||||
for (int i = al; i; i--)
|
||||
q = q * 10 + a[i];
|
||||
|
||||
return q % 8 == 0;
|
||||
}
|
||||
int main() {
|
||||
int N;
|
||||
cin >> N;
|
||||
while (N--) {
|
||||
al = 0;
|
||||
LL x;
|
||||
cin >> x;
|
||||
if (check(x))
|
||||
cout << "T" << endl;
|
||||
else
|
||||
cout << "F" << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
104
GESP/Level4/GESP202306/4_2.cpp
Normal file
104
GESP/Level4/GESP202306/4_2.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 256;
|
||||
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());
|
||||
if (res.empty())
|
||||
return "00";
|
||||
if (res.size() == 1)
|
||||
return "0" + res;
|
||||
return res;
|
||||
}
|
||||
|
||||
// 在重新排完序的数据中找出离q最近的灰阶索引号
|
||||
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)]++; // 记录桶
|
||||
}
|
||||
}
|
||||
|
||||
// 开始查找前16位数量多的数字,那我就直接找16次最大的数字是多少,找到后我就把它的数量修改为0
|
||||
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);
|
||||
}
|
||||
|
||||
// 输出前16位的灰阶索引号
|
||||
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);
|
||||
// 这个数字,与res中哪个数字最接近,接近的含义是差的绝对值最小
|
||||
cout << find(q);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
BIN
GESP/Level4/GESP202306/GESP C++四级认证试卷2023年6月.pdf
Normal file
BIN
GESP/Level4/GESP202306/GESP C++四级认证试卷2023年6月.pdf
Normal file
Binary file not shown.
102
GESP/Level4/GESP202306/Test.cpp
Normal file
102
GESP/Level4/GESP202306/Test.cpp
Normal file
@@ -0,0 +1,102 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 256;
|
||||
int b[N];
|
||||
string c[N]; // 原字符串数组
|
||||
vector<int> v;
|
||||
|
||||
int toDec(string s) { // 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(string s) {
|
||||
int x = toDec(s);
|
||||
int mi = INT_MAX, mp = 0;
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
if (abs(x - v[i]) < mi) {
|
||||
mi = abs(x - v[i]);
|
||||
mp = i;
|
||||
}
|
||||
}
|
||||
if (mp >= 10)
|
||||
return (char)(mp - 10 + 'A');
|
||||
return (char)(mp + '0');
|
||||
}
|
||||
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) {
|
||||
char x = s[j], y = s[j + 1];
|
||||
string t;
|
||||
t.push_back(x);
|
||||
t.push_back(y);
|
||||
// 我要把两位字符串的十六进制数转为十进制
|
||||
b[toDec(t)]++;
|
||||
}
|
||||
}
|
||||
// 记录前十六名都有谁
|
||||
|
||||
// 我需要知道哪个灰阶颜色最多,前十六位都有谁?
|
||||
for (int i = 1; i <= 16; i++) {
|
||||
int mx = 0, mp = 0; // 每次都找最大值,并且记录最大值所在的pos位置
|
||||
for (int j = 0; j < 256; j++) {
|
||||
if (b[j] > mx) {
|
||||
mx = b[j];
|
||||
mp = j;
|
||||
}
|
||||
}
|
||||
// 因为老大找出了,就不需要下次再参与评比了,否则它会一直是老大
|
||||
b[mp] = 0;
|
||||
v.push_back(mp); // 把前十六名都记录下来
|
||||
}
|
||||
|
||||
for (int i = 0; i < v.size(); i++) {
|
||||
string s = toHex(v[i]);
|
||||
if (s.size() == 1)
|
||||
s = "0" + s;
|
||||
cout << s;
|
||||
}
|
||||
cout << endl;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
string s = c[i];
|
||||
for (int j = 0; j < s.size(); j += 2) {
|
||||
char x = s[j], y = s[j + 1];
|
||||
string t;
|
||||
t.push_back(x);
|
||||
t.push_back(y);
|
||||
cout << find(t);
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
26
GESP/Level4/GESP202306/Test2.cpp
Normal file
26
GESP/Level4/GESP202306/Test2.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
|
||||
// 十进制转十六进制
|
||||
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());
|
||||
if (res.empty())
|
||||
return "00";
|
||||
if (res.size() == 1)
|
||||
return "0" + res;
|
||||
return res;
|
||||
}
|
||||
int main() {
|
||||
for (int x = 0; x <= 255; x++)
|
||||
cout << toHex(x) << endl;
|
||||
return 0;
|
||||
}
|
||||
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