C++代码实现正整数排序:首位数字从小到大,相同首位数字从小到大
#include
bool cmp(int a, int b) { if (a / 10 != b / 10) { return a / 10 < b / 10; } else { return a % 10 < b % 10; } }
int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, cmp); for (int i = 0; i < n; i++) { cout << a[i] << ' '; } return 0; }
原文地址: https://www.cveoy.top/t/topic/ov7S 著作权归作者所有。请勿转载和采集!