-
Notifications
You must be signed in to change notification settings - Fork 0
/
LargestNUM.cpp
59 lines (58 loc) · 1.35 KB
/
LargestNUM.cpp
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
53
54
55
56
57
58
59
#include<iostream>
#include<string>
#include<vector>
#include <cctype>
#include<algorithm>
#include<math.h>
using namespace std ;
typedef struct ListNode{
int val;
ListNode * next;
} ListNode;
class Solution {
public:
string largestNumber(vector<int> &num) {
vector<string> cur_str;
string res;
int i,j,size=num.size();
char B[256]="";
for(i=0;i<size;i++){
sprintf(B,"%d",num[i]);
cur_str.push_back(B);
}
sort(cur_str.begin(),cur_str.end());
for(j=0;j<size;j++)
for(i=0;i<size;i++){
if(i<size-1&&(cur_str[i]+cur_str[i+1])>(cur_str[i+1]+cur_str[i]))
swap(cur_str[i],cur_str[i+1]);
}
for(i=size-1;i>=0;i--){
res+=cur_str[i];
}
if(size&&cur_str[size-1]=="0")
res="0";
return res;
}
void print(){
vector<int> A;
A.push_back(74);
A.push_back(21);
A.push_back(33);
A.push_back(51);
A.push_back(77);
A.push_back(51);
A.push_back(90);
A.push_back(60);
A.push_back(5);
A.push_back(56);
cout<<largestNumber(A)<<endl;
}
};
int main()
{
Solution test;
// cout<<test.Low("A man, a plan, a canal: Panama")<<endl;
test.print();
// cout<<atoi("2147483648")<<endl;
system("pause");
}