首页 > 代码库 > 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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。