P1012 [NOIP 1998 提高组] 拼数https://www.luogu.com.cn/problem/P1012

原题为:设有 n 个正整数 a1​…an​,将它们联接成一排,相邻数字首尾相接,组成一个最大的整数。

此处使用到了字符串的字典排序,即每一位都会与另一个数的ascii码来比较,例如: 2 6 ,2小于6的ascii码,所以2<6,此时就产生了一个问题,回到800 > 8,所以要另行判断,以下为cmp函数的代码:

bool cmp(const string a, const string b) {
	cout << a + b << " " << b + a << endl; 
	return a + b > b + a;
}

haihaihai

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注