排序后无法变成理想顺序
查看原帖
排序后无法变成理想顺序
1053122
shy_lihui楼主2025/1/8 13:32
#include<bits/stdc++.h>
using namespace std;
int A,B,C,D,E;
int s[500];
vector<string> v;
int getsum(const string &s)
{
	int cnt=0;
	for(char i:s)
	{
		cnt+=s[int(i)];
	}
	return cnt;
}
bool cmp(const string &x,const string &y)
{
	int X=getsum(x);
	int Y=getsum(y);
	if(X==Y)
	{
		return x<y;
	}
	return X>Y;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>A>>B>>C>>D>>E;
	s['A']=A;
	s['B']=B;
	s['C']=C;
	s['D']=D;
	s['E']=E;
	
	for(int a=0;a<=1;a++)
	{
		for(int b=0;b<=1;b++)
		{
			for(int c=0;c<=1;c++)
			{
				for(int d=0;d<=1;d++)
				{
					for(int e=0;e<=1;e++)
					{
						string p{};
						if(a)
						{
							p+="A";
						}
						if(b)
						{
							p+="B";
						}
						if(c)
						{
							p+="C";
						}
						if(d)
						{
							p+="D";
						}
						if(e)
						{
							p+="E";
						}
						if(!p.empty())
						{
							v.push_back(p);
						}
					}
				}
			}
		}
	}
	sort(v.begin(),v.end(),cmp);
	for(auto i:v)
	{
		cout<<i<<"\n";
	}
	return 0;
}
2025/1/8 13:32
加载中...