首页 > 代码库 > UVa 10905 Children's Game

UVa 10905 Children's Game

注意!这不是单纯的字典序排序,比如90、9,应该是990最大

对字符串排序蛋疼了好久,因为别人说string很慢,所以一直没有用过。

看别人用string还是比较方便的,学习一下

对了,这里的cmp函数写的还是很简洁的,比我写的要好得多

 

 1 #define LOCAL 2 #include <iostream> 3 #include <cstdio> 4 #include <cstring> 5 #include <algorithm> 6 using namespace std; 7  8 bool cmp(const string &a, const string &b) 9 {10     return (a + b > b + a);11 }12 13 int main(void)14 {15     #ifdef LOCAL16         freopen("10905in.txt", "r", stdin);17     #endif18 19     int n;20     string str[52];21     while(cin >> n && n)22     {23         for(int i = 0; i < n; ++i)24             cin >> str[i];25         sort(str, str + n, cmp);26         for(int i = 0; i < n; ++i)27             cout << str[i];28         cout << endl;29     }30     return 0;31 }
代码君

 

UVa 10905 Children's Game