UVa 10905 Children's Game
注意!这不是单纯的字典序排序,比如90、9,应该是990最大
对字符串排序蛋疼了好久,因为别人说string很慢,所以一直没有用过。
看别人用string还是比较方便的,学习一下
对了,这里的cmp函数写的还是很简洁的,比我写的要好得多
- #define LOCAL
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <algorithm>
- using namespace std;
- bool cmp(const string &a, const string &b)
- {
- return (a + b > b + a);
- }
- int main(void)
- {
- #ifdef LOCAL
- freopen("10905in.txt", "r", stdin);
- #endif
- int n;
- string str[];
- while(cin >> n && n)
- {
- for(int i = ; i < n; ++i)
- cin >> str[i];
- sort(str, str + n, cmp);
- for(int i = ; i < n; ++i)
- cout << str[i];
- cout << endl;
- }
- return ;
- }
代码君
UVa 10905 Children's Game的更多相关文章
- uva 10905 Children's Game (排序)
题目连接:uva 10905 Children's Game 题目大意:给出n个数字, 找出一个序列,使得连续的数字组成的数值最大. 解题思路:排序,很容易想到将数值大的放在前面,数值小的放在后面.可 ...
- UVA 10905 Children's Game 孩子的游戏 贪心
题意:给出N个数,要求把它们拼凑起来,让得到的数值是最大的. 只要分别比较两个数放前与放后的值的大小,排序后输出就可以了. 比如123和56,就比较12356和56123的大小就行了. 写一个比较函数 ...
- 【字符串排序,技巧!】UVa 10905 - Children’s Game
There are lots of number games for children. These games are pretty easy to play but not so easy to ...
- UVA 10905 Children's Game (贪心)
Children's Game Problem Description There are lots of number games for children. These games are pre ...
- UVa 10905 - Children's Game 排序,题目没有说输入是int 难度: 0
题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...
- UVa 10905 - Children's Game(求多个正整数排列后,所得的新的数字的极值)
4thIIUCInter-University Programming Contest, 2005 A Children’s Game Input: standard input Output: st ...
- UVA 10905 Children's Game (贪心)
贪心,假如任意给出一个序列,如果两两交换了以后会变大,那么就交换,直到不能交换为止. #include<bits/stdc++.h> using namespace std; ; stri ...
- Children's Game UVA - 10905
看90,956这样的串,在比较完之前,就确定大小的,必定选大的放在前.而x=98,y=980;这样的,比较x+y和y+x的大小.如果x+y更小,y就放前. #include <iostream& ...
- 10905 - Children's Game
4th IIUC Inter-University Programming Contest, 2005 A Children’s Game Input: standard input Output: ...
随机推荐
- Why we have to use epsg:900913 in OpenLayers
reference:http://docs.openlayers.org/library/spherical_mercator.html epsg:900913 is spicfy the Soher ...
- 使用行为树(Behavior Tree)实现网游奖励掉落系统
原地址:http://blog.csdn.net/akara/article/details/6165421 [原创]使用行为树(Behavior Tree)实现网游奖励掉落系统by AKara 20 ...
- 通过 Mesos、Docker 和 Go,使用 300 行代码创建一个分布式系统
[摘要]虽然 Docker 和 Mesos 已成为不折不扣的 Buzzwords ,但是对于大部分人来说它们仍然是陌生的,下面我们就一起领略 Mesos .Docker 和 Go 配合带来的强大破坏力 ...
- 【剑指offer】和为S的连续整数序列
找到所有和为S的连续整数序列,序列长度>=2 我的思路:数学法,限定首元素范围,计算序列长度. 书上解法:用small和big两个游标记录序列的开始和结束位置,调整游标. 我的解法: /* 直 ...
- Lua的require和module小结
Lua的require和module小结 module特性是lua5.1中新增的,用于设置Lua文件自己的模块,最常用的方式是module(name,package.seeall),有时候lua文件 ...
- VS输入法问题
问题描述:启动VS,打开Winform等的界面设计,无法为控件输入中文,另外,运行程序,无法在TextBox等控件中输入中文: 本人的系统环境:Win7旗舰版,VS2008.VS2010和VS2012 ...
- Android Non-UI to UI Thread Communications(Part 1 of 5)
original:http://www.intertech.com/Blog/android-non-ui-to-ui-thread-communications-part-1-of-5/ ANDRO ...
- DFS/BFS+思维 HDOJ 5325 Crazy Bobo
题目传送门 /* 题意:给一个树,节点上有权值,问最多能找出多少个点满足在树上是连通的并且按照权值排序后相邻的点 在树上的路径权值都小于这两个点 DFS/BFS+思维:按照权值的大小,从小的到大的连有 ...
- 【Apache运维基础(4)】Apache的Rewrite攻略(1)
简述 Rewirte主要的功能就是实现URL的跳转,它的正则表达式是基于Perl语言.可基于服务器级的(httpd.conf)和目录级的 (.htaccess)两种方式.如果要想用到rewrite模块 ...
- [iOS]利用系统NSRegularExpression使用正则表达式
// Created by 李东旭 on 16/1/22. // Copyright © 2016年 李东旭. All rights reserved. // #import <UIKit/UI ...