大佬求调(玄关
  • 板块学术版
  • 楼主sunzhaoyang
  • 当前回复2
  • 已保存回复2
  • 发布时间2024/8/4 21:23
  • 上次更新2024/8/4 22:40:55
查看原帖
大佬求调(玄关
977229
sunzhaoyang楼主2024/8/4 21:23

B3851 [GESP202306 四级] 图像压缩

#include<bits/stdc++.h>
using namespace std;
int n,l;
string s,cc[21];
struct node
{
	int bh,gs=0;
	string sc;
}note[256];
bool cmp(node _A,node _B)
{
	if(_A.gs!=_B.gs)
	{
		return _A.gs>_B.gs;
	}
	return _A.bh<_B.bh;
}
int _16_go_10(string _16) 
{
	int _10;
	stringstream ss;
	ss<<hex<<_16;
	ss>>_10;
	return _10;
}

int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		cc[i]=s;
		l=s.length();
		for(int j=0;j<l;j+=2)
		{
			string s1="";
			s1+=s[j];
			s1+=s[j+1];
			int x=_16_go_10(s1);
			note[x].sc=s1;
			note[x].bh=x;
			note[x].gs++;
		}	
	}
	sort(note,note+255,cmp);
	for(int i=0;i<16;i++)
	{
		cout<<note[i].sc;
	}
	cout<<endl;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<l;j+=2)
		{
			string s2="";
			char gl;
			s2+=cc[i][j];
			s2+=cc[i][j+1];
			int just_soso=_16_go_10(s2),minn=999;
			for(int k=0;k<16;k++)
			{
				if(abs(note[k].bh-just_soso)<minn)
				{
					minn=abs(note[k].bh-just_soso);
					if(k<=9)
					{
						gl=k;
					}
					else gl=char(k-10+'A');
				}
			}
			cout<<gl;
		}
		cout<<endl;
	}
	return 0;
}
2024/8/4 21:23
加载中...