75分代码 求大佬指导
查看原帖
75分代码 求大佬指导
1435695
Mu_________楼主2024/8/31 18:26
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#include<stdlib.h>


int weishu(int long long x)
{
	if (x > 9)
		return 1 + weishu(x / 10);
	else
		return 1;
}

int  cmp(const void* e1, const void* e2)
{
	int a = 0, b = 0;
	a=weishu(*(long long*)e1);
	b=weishu(*(long long*)e2);
	int a1 = (int)pow(10, (a-b));
	int b1 = (int)pow(10, (b-a));
	if (a == b)
		return  (int)((*(long long*)e2) - (*(long long*)e1));
	else if(a>b)
		return (int)((*(long long*)e2* a1) - (*(long long*)e1));
	   else
		return (int)((*(long long*)e2) - (*(long long*)e1*b1));


}
int main()
{
	int n = 0;
	scanf("%d", &n);
	int long long arr[20] = { 0 };     //每行表示一个数      每一列的小个子存一位数
	int i = 0;
	for (i = 0; i <= n - 1; ++i)
		scanf("%lld", &arr[i]);

	qsort(arr, n, sizeof(arr[0]), cmp);  //快速排序  降序
	
	for (i = 0; i <= n - 1; ++i)
	{
		printf("%lld", arr[i]);
	}

	return 0;
}
2024/8/31 18:26
加载中...