求大佬调试
查看原帖
求大佬调试
755412
DPG_DPG123楼主2023/6/23 11:10
# include <bits/stdc++.h>
using namespace std;
long long n;
string ls[100];

int d(char i) {
	return i - 48;
}

bool cmp(string a, string b) {
	for (int i = 0; i < min(a.size(), b.size()); i++) {
		if (d(a[i]) > d(b[i]))
			return b < a;
		if (d(a[i]) < d(b[i]))
			return a < b;
	}
	// 没有选出结果,那就将位数多的放前面
	if (a.size() > b.size())
		return b < a;
	else
		return a < b; // 这里会有两种情况:a.size()==b.size() 和 a.size() < b.size()都可按此处理
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> ls[i];
	sort(ls, ls + n, cmp);
	for (int i = 0; i < n; i ++)
		cout << ls[i];
	return 0;
}

https://www.luogu.com.cn/record/113156911

2023/6/23 11:10
加载中...