洛谷——P1012 拼數
阿新 • • 發佈:2017-07-04
sca stream pre i++ n) pac problem lan ace
https://www.luogu.org/problem/show?pid=1012#sub
題目描述
設有n個正整數(n≤20),將它們聯接成一排,組成一個最大的多位整數。
例如:n=3時,3個整數13,312,343聯接成的最大整數為:34331213
又如:n=4時,4個整數7,13,4,246聯接成的最大整數為:7424613
輸入輸出格式
輸入格式:
第一行,一個正整數n。
第二行,n個正整數。
輸出格式:
一個正整數,表示最大的整數
輸入輸出樣例
輸入樣例#1:3 13 312 343輸出樣例#1:
34331213
1 #include <algorithm> 2 #include <iostream> 3 #include <cstring> 4 #include <string> 5 #include <cstdio> 6 7 using namespace std; 8 9 bool cmp(string a,string b) 10 { 11 return a+b>b+a; 12 } 13 14 int n; 15 string s[2333]; 16 17 intmain() 18 { 19 scanf("%d",&n); 20 for(int i=1;i<=n;i++) cin>>s[i]; 21 sort(s+1,s+1+n,cmp); 22 for(int i=1;i<=n;i++) cout<<s[i]; 23 return 0; 24 }
洛谷——P1012 拼數