题解 | #大整数排序#
大整数排序
https://www.nowcoder.com/practice/b744af632ac4499aa485d7bb048bb0aa
#include<iostream> #include<string> #include<algorithm> using namespace std; bool comp(string rhs, string lhs){ if (rhs.size() < lhs.size()){ return true; } else if (rhs.size() == lhs.size() && rhs < lhs){ return true; } else{ return false; } } int main(){ int n; while (scanf("%d", &n) != EOF){ string arr[100]; for (int i = 0; i < n; i++){ cin >> arr[i]; } sort(arr, arr + n,comp); for (int i = 0; i < n; i++){ cout << arr[i] << endl; } } }