網頁

2014年2月17日 星期一

UVa 10905 Children's Game

想法:
  對每個數字做排序,排序用STL_sort,cmp函數裡面就比較a和b兩個數字是(ab)比較大還是(ba)比較大決定排序方式,最後依序輸出即可。



#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
bool cmp(string a, string b)
{
return (a+b) > (b+a);
}
int main()
{
ios::sync_with_stdio(false);
int n;
while (cin >> n){
if (!n) break;
vector<string> num;
string temp;
for (int i=0; i<n; ++i){
cin >> temp;
num.push_back(temp);
}
sort(num.begin(),num.end(),cmp);
for (int i=0; i<n; ++i)
cout << num[i];
cout << endl;
}
return 0;
}

沒有留言:

張貼留言