首页 > 试题广场 >

大整数排序

[编程题]大整数排序
  • 热度指数:18161 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
对N个长度最长可达到1000的数进行排序。

输入描述:
输入第一行为一个整数N,(1<=N<=100)。
接下来的N行每行有一个数,数的长度范围为1<=len<=1000。
每个数都是一个正数,并且保证不包含前缀零。


输出描述:
可能有多组测试数据,对于每组数据,将给出的N个数从小到大进行排序,输出排序后的结果,每个数占一行。
示例1

输入

3
11111111111111111111111111111
2222222222222222222222222222222222
33333333

输出

33333333
11111111111111111111111111111
2222222222222222222222222222222222
头像 鱼儿恋上水
发表于 2020-04-06 16:22:51
简单的字符串排序,用到了sort()函数,关键在于cmp规则的编写 #include <iostream> #include <cstring> #include <string> #include <algorithm> using namespac 展开全文
头像 CyberAoao
发表于 2023-03-20 10:34:07
直接给每个数字前面添0到相同长度,再直接比较字符串,简单粗暴_(:з」∠)_ #include <iostream> #include <string> #include <vector> #include <algorithm> using name 展开全文
头像 ruuioche
发表于 2024-01-31 20:15:27
#include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> typedef struct in_num { char num[1001]; 展开全文
头像 木何
发表于 2023-03-05 21:44:08
#include<iostream> #include<cstring> using namespace std; bool jude(string s1, string s2) { //判断s1是否比s2大 if (s1.size() < s2.size( 展开全文
头像 在考古的小鱼干很有气魄
发表于 2023-03-07 12:37:00
#include <bits/stdc++.h> #define MAX 1000 using namespace std; bool cmp(vector<int> a, vector<int> b) { int lena = a.size(), le 展开全文
头像 热心市民小喷
发表于 2020-03-05 17:11:27
//思路:最近在练习大整数,所以用大整数,可以直接用string类的比较大小的方法,长度相同的比较每一位,不同的则长的大 //string 用大整数储存法,然后定义结构体,重载<符号, //用sort进行排序 #include<iostream> #include< 展开全文
头像 牛客440904392号
发表于 2024-10-07 17:09:01
//C++版代码 #include <iostream> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(null 展开全文
头像 爱交友的马后炮炮手在创作
发表于 2024-03-03 14:48:46
#include <stdio.h> #include <string.h> int comp(char a[100],char b[100]){ int i=strlen(a),j=strlen(b); if(i>j)return 1; els 展开全文
头像 lovekang
发表于 2024-09-09 10:57:46
加油,就是字符串排序。不过这里我们需要稍微改进一下默认的排序。 #include <iostream> #include <algorithm> #include <vector> #include <string.h> using namespace 展开全文
头像 小朱666
发表于 2023-09-22 20:07:49
#include <cstdio> #include <iostream> #include<cstring> #include<stdlib.h> using namespace std; char str[1000][1000]; int cm 展开全文