1806 Max number string and sort function usage, 1806 sort
1. C ++ built-in sort function usage
The sort function has three parameters:
(1) The first is the starting address of the array to be sorted.
(2) The second is the ending address (the last address to be sorted)
(3) The third parameter is the sorting method. It can be from large to small, but from small to large. The third parameter can also be left blank. The default sorting method is from small to large.
Sort function template: sort (start, end, sorting method)
The third parameter can be used to tell the program the sorting principle you adopt.
Less <data type> () // sort data in ascending order
Greater <data type> () // sort data in ascending order
Example: (using the simplified model as an example)
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 int main() 5 { 6 char a[11]="asdfghjklk"; 7 sort(a,a+10,greater<char>()); 8 for(int i=0;i<10;i++) 9 cout<<a[i];10 return 0;11 }
Output result: slkkjhgfda
2. Special Use of string
String a = "12 ";
String B = "34 ";
String A-B = "1234 ";
String B plus a = "3412 ";
3. Maximum number of 1806
Description
Description
There are n integers (n ≤ 20) and join them into a row to form a maximum of multiple integers.
Input description
Input Description
The first line is a positive integer n.
The second line contains n positive integers separated by spaces.
Output description
Output Description
The number of digits connected.
Sample Input
Sample Input
Sample 1:
3
13 312 343
Sample 2:
4
7 13 4 246
Sample output
Sample Output
Sample 1:
34331213
Sample 2:
7424613
Data range and prompt
Data Size & Hint
N ≤ 20
1 #include<iostream> 2 #include<algorithm> 3 using namespace std; 4 string a[25]; 5 6 bool cmp(string a,string b) 7 { 8 return a+b>b+a; 9 }10 11 int main()12 {13 int n,i,j;14 cin>>n; 15 for(i=0;i<n;i++){16 cin>>a[i];17 }18 sort(a,a+n,cmp);19 for(j=0;j<n;j++){20 cout<<a[i];21 }22 cout<<endl;23 return 0;24 }