Maximum P1107 integer and P1107 integer

Source: Internet
Author: User

Maximum P1107 integer and P1107 integer
Description

There are n positive integers (n <= 20) connected into a row to form a maximum of multiple integers.

For example, when n = 3, the maximum integer connected by 3 integers 13,312,343 is 34331213.

For example, when n = 4, the maximum integer of the 4 integers 7, 13, and 4,246 is 7424613.

Input/Output Format Input Format:

Nn count

Output Format:

Multiple Digits connected

Input and Output sample Input example #1:
313 312 34347 13 4 246
Output sample #1:
343312137424613

Stl is good. I always feel where I have done this.
Note that the condition is not a> B. Otherwise
3
9 90 9 this group of data cannot pass !!
 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<algorithm> 6 using namespace std; 7 const int MAXN=21; 8 int read(int & n) 9 {10     char c='.';int x=0,flag=0;11     while(c<'0'||c>'9')12     {13         c=getchar();14         if(c=='-')flag=1;15     }16     while(c>='0'&&c<='9')17     {18         x=x*10+(c-48);19         c=getchar();20     }21     if(flag==1)n=-x;22     else n=x;23 }24 string s[21];25 int comp(const string & a,const string & b)26 {27     return a+b>b+a;28 }29 int main()30 {31     int n;32     while(cin>>n)33     {34         for(int i=1;i<=n;i++)35             cin>>s[i];36         sort(s+1,s+n+1,comp);37         for(int i=1;i<=n;i++)38         cout<<s[i];    39     }40     41     return 0;42 }

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.