1. 程式人生 > >CODE[VS] 1860 最大數 1998年NOIP全國聯賽提高組

CODE[VS] 1860 最大數 1998年NOIP全國聯賽提高組

body all 真的 題目 class namespace nbsp out tro

題目描述 Description

  設有n個正整數(n≤20),將它們聯接成一排,組成一個最大的多位整數。

輸入描述 Input Description

  第一行一個正整數n。

  第二行n個正整數,空格隔開。

輸出描述 Output Description

  連接成的多位數。

樣例輸入 Sample Input

Sample 1:

3

13 312 343

Sample 2:

4

7 13 4 246

樣例輸出 Sample Output

Sample 1:

34331213

Sample 2:

7424613

數據範圍及提示 Data Size & Hint

n≤20

各位客官註意了啊!

哇,這題,,在我以為非常麻煩,要從最前面一位兒開始逐個比較,

把大的放前面,,,簡直快要崩潰的時候,,

突然!!!

發現一個瞎搞的方法!!!

太鬼畜了!!!

cmp函數居然還能這麽寫!!!

這也太簡單了吧!!!

字符串,直接比較啊!!!

wait,!這。。。我之前好像見過。。。

請自行感觸吧2333

代碼:

 1 #include<iostream>
 2 #include<cstdio>
 3
#include<cmath> 4 #include<algorithm> 5 #include<cstring> 6 #include<queue> 7 using namespace std; 8 9 int n; 10 string a[22]; 11 12 bool cmp(string x,string y) 13 { 14 return x+y>y+x; 15 } 16 17 int main() 18 { 19 scanf("%d",&n); 20 for
(int i=1;i<=n;++i) 21 cin>>a[i]; 22 sort(a+1,a+n+1,cmp); 23 for(int i=1;i<=n;++i) 24 cout<<a[i]; 25 return 0; 26 }


如果你不開心,那我就把右邊技術分享圖片這個帥傻子分享給你吧,

你看,他這麽好看,那麽深情的望著你,你還傷心嗎?

真的!這照片盯上他五秒鐘就想笑了。

一切都會過去的。

時間時間會給你答案2333

CODE[VS] 1860 最大數 1998年NOIP全國聯賽提高組