样例都炸了!!!实在找不出错了!!!
查看原帖
样例都炸了!!!实在找不出错了!!!
946050
congtianyi_1203楼主2025/6/24 17:54
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct node {
	int x, y;
} ten[256];
bool cmp(node a, node b) {
	if (a.x != b.x) return a.x > b.x;
    return a.y > b.y;
}
string to_hex(int num, int width = 2) {
	static const char* digits = "0123456789ABCDEF";
	string result(width, '0');
	for (int i = width - 1; i >= 0; --i) {
		result[i] = digits[num & 0xF];
		num >>= 4;
	}
	return result;
}
signed main() {
	int n, convert[16], cnt = 0, t;
	cin >> n;
	t = n;
	int d[n][n];
	memset(ten, 0, sizeof(ten));
	for (int i = 0; i < 256; i++) ten[i].y = i;
	while (t--) {
		string a = "0x", b;
		cin >> b;
		for (int i = 0; i < b.size(); i++) {
			a += b[i];
			if (i % 2 != 0) {
				ten[stoi(a)].x++;
				d[n - t - 1][cnt] = stoi(a);
				cnt++;
			} else a = "0x";
		}
		cnt = 0;
	}
	sort(ten, ten + 256, cmp);
	for (int i = 0; i < 16; i++) {
		cout << to_hex(ten[i].y) << " ";
		convert[i] = ten[i].y;
	}
	cout << endl;
	sort(convert, convert + 16);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			int x = 257, y;
			for (int k = 0; k < 16; k++) {
				if (x > abs(d[i][j] - convert[k])) {
					x = abs(d[i][j] - convert[k]);
					y = k;
				}
			}
			cout << to_hex(y, 1);
		}
		cout << endl;
	}
	return 0;
}
2025/6/24 17:54
加载中...