-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bigsort
52 lines (40 loc) · 1.09 KB
/
Bigsort
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Consider an array of numeric strings, , where each string is a positive number with anywhere from to digits.
Sort the array's elements in non-decreasing (i.e., ascending) order of their real-world integer values and print
each element of the sorted array on a new line.
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
bool compare(string s1,string s2){
long long int size_s1=s1.size();
long long int size_s2=s2.size();
int dig1,dig2;
if(size_s1!=size_s2)
return size_s1<size_s2;
else{
for(int i=0; i<size_s1;i++){
dig1=s1[i]-'0';
dig2=s2[i]-'0';
if(dig1==dig2)
continue;
else
return dig1<dig2;
}
return true;
}
}
int main(){
int n;
cin >> n;
vector<string> arr(n);
for(int i = 0; i < n; i++){
cin >> arr[i];
}
sort(arr.begin(),arr.end(),compare);
for(int i=0;i<n;i++)
cout<<arr[i]<<endl;
return 0;
}