對每個數字做排序,排序用STL_sort,cmp函數裡面就比較a和b兩個數字是(ab)比較大還是(ba)比較大決定排序方式,最後依序輸出即可。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
沒有留言:
張貼留言