Uva10905 Children's Game (C++String的运运用呀...)

.


Children's Game
Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

Submit Status

Description


题意:

给定n个正整数,把它们连接成一个最大的整数.比如,123,124,556,90有24种连接方法,最大的结果为9 056 124 123

方法:原来本来打算用strcmp排序,后来发现错了,如9,90,按照srecmp排序的到的是909,而非最大值990,网上看到大神的博客用了c++的string,.


AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define N 55

string word[N];
int n;

bool cmp(string a ,string b)
{
   return a+b > b+a;
}

int main()
{
   while(scanf("%d",&n)!=EOF && n)
   {
      for(int i=0; i<n; i++)
         cin >> word[i];
      sort(word , word+n , cmp);
      for(int i=0; i<n; i++)
         cout << word[i];
      cout << endl;
   }
   return 0;
}



.

你可能感兴趣的:(game,Childrens,Uva10905)