样例可过,全RE
查看原帖
样例可过,全RE
1173385
_czy2023_楼主2024/11/18 14:06
#include<bits/stdc++.h>
using namespace std;

const int N=2e1+5;
struct node{
	int z/*值*/,gs/*出现次数*/;
	bool operator<(const node b)const{//自定义排序 
		if(gs==b.gs)return z<b.z;
		return gs>b.gs;
	}
}cl[256];
int n,m,x,g,a[N][N];
bool b[256];
string s,ss;

int f(int x){
	for(int i=1;i<=g;i++)
		if(cl[i].z==x)return i;//查找对应数的编号 
}

int main(){
	
	cin>>n;
	getchar();
	for(int i=1;i<=n;i++){//输入 
		getline(cin,s);
		m=s.size();
		for(int j=0;j<m;j+=2){
			ss=s[j],ss+=s[j+1];
			x=stoi(ss,nullptr,16);//十六进制化为十进制 
			a[i][j/2+1]=x;
			//统计个数 
			if(!b[x])
				b[x]=1,cl[++g].z=x;
			cl[f(x)].gs++;
		}
		m/=2;
	}
	//第一行输出 
	sort(cl+1,cl+1+g);
	for(int i=1;i<=16;i++)
		printf("%02X",cl[i].z);
	cout<<endl;
	//灰度 
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			int bh,mi=256;
			for(int k=1;k<=16;k++){
				int ch=abs(a[i][j]-cl[k].z);
				if(ch<mi)
					bh=k,mi=ch;
				else if(ch==mi)
					if(cl[k].z<cl[bh].z)bh=k;
			}
			a[i][j]=bh-1;
		}
	
	for(int i=1;i<=n;i++,cout<<endl)
		for(int j=1;j<=m;j++)
			printf("%X",a[i][j]);
	
	return 0;
}
2024/11/18 14:06
加载中...