問題 G: 最大整數
時間限制: 1 Sec 內存限制: 128 MB提交: 67 解決: 18
[提交][狀態][討論版]
題目描述
輸入
輸出
樣例輸入
3
13 312 343
樣例輸出
34331213
自己做的時候wa了好多次,剛剛開始學貪心,還學得很不好。這裏可以給大家幾組測試數據:3 10 100 100; 5 100 102 9 12 150;。。。
這題一直很頭疼比較函數的寫法,嘗試了int,也嘗試了char數組,最後還是學到了string在這裏的妙用,感覺有必要記錄一下。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;
struct node{
string a;
};
inline bool cmp(node x,node y)
{
if(x.a+y.a>y.a+x.a)return 1;
else return 0;
}
int main()
{
int n;
while(cin>>n)
{
int t=n,r=0;
node m[25];
while(t--)
{
cin>>m[r++].a;
}
sort(m,m+n,cmp);
for(int i=0;i<n;i++) cout<<m[i].a;
printf("\n");
}
return 0;
}