题解 | #大整数排序#
大整数排序
https://www.nowcoder.com/practice/b744af632ac4499aa485d7bb048bb0aa
#include <stdio.h>
#include <string.h>
int main() {
int n;
while (scanf("%d ", &n) != EOF) { // 注意 while 处理多个 case
// 64 位输出请用 printf("%lld") to
char array[n][1000];
int i = 0, j;
//读入数据
for (i = 0; i < n; i++) {
gets(array[i]);
//printf("%s\n",array[i]);
//scanf("%s", array[i]);
}
//冒泡排序
char temp[1000];
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i - 1; j++) {
//比较大小
if ((strlen(array[j]) == strlen(array[j + 1]) &&
strcmp(array[j], array[j + 1]) > 0) ||
strlen(array[j]) > strlen(array[j + 1])) {
//交换位置
memset(temp, 0, sizeof temp);
strcpy(temp, array[j + 1]);
memset(array[j + 1], 0, sizeof array[j + 1]);
strcpy(array[j + 1], array[j]);
memset(array[j], 0, sizeof array[j]);
strcpy(array[j], temp);
}
}
}
for (i = 0; i < n; i++) {
printf("%s\n", array[i]);
}
}
return 0;
}


