题解 | #大整数排序#
大整数排序
https://www.nowcoder.com/practice/b744af632ac4499aa485d7bb048bb0aa
#include <cstdio> #include <iostream> #include<cstring> #include<stdlib.h> using namespace std; char str[1000][1000]; int cmp(const void *a, const void *b) { int la = strlen((char*)a); int lb = strlen((char*)b); if(la != lb) return la - lb; else return strcmp((char *)a, (char *)b); } int main() { int n; while(scanf("%d", &n) != EOF) { for(int i = 0; i < n; i++) scanf("%s", str[i]); qsort(str, n, sizeof(str[0]), cmp); for(int i = 0; i < n; i++) printf("%s\n", str[i]); } }