uva 10905 Children's Game (排序)
题目连接:uva 10905 Children's Game
题目大意:给出n个数字, 找出一个序列,使得连续的数字组成的数值最大。
解题思路:排序,很容易想到将数值大的放在前面,数值小的放在后面。可是,该怎么判断数值的大小(判断数值大小不能单单比较两个数的大小,比如遇到:1 、10的情况)。其实,判断一个不行,那就将两个合在一起考虑就可以了(就是比较110合101的大小来普判断1 放前面还是10放前面)。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = 1005; struct number {
char s[N];
}num[N]; bool cmp(const number &a, const number &b) {
char str1[N], str2[N];
strcpy(str1, a.s);
strcat(str1, b.s);
strcpy(str2, b.s);
strcat(str2, a.s);
return strcmp(str1, str2) > 0;
} int main() {
int n;
while (scanf("%d", &n), n) {
// Init;
memset(num, 0, sizeof(num)); // Read;
for (int i = 0; i < n; i++)
scanf("%s", num[i].s); sort(num, num + n, cmp); for (int i = 0; i < n; i++)
printf("%s", num[i].s);
printf("\n");
}
return 0;
}
uva 10905 Children's Game (排序)的更多相关文章
- 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 孩子的游戏 贪心
题意:给出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(求多个正整数排列后,所得的新的数字的极值)
4thIIUCInter-University Programming Contest, 2005 A Children’s Game Input: standard input Output: st ...
- UVa 10905 Children's Game
注意!这不是单纯的字典序排序,比如90.9,应该是990最大 对字符串排序蛋疼了好久,因为别人说string很慢,所以一直没有用过. 看别人用string还是比较方便的,学习一下 对了,这里的cmp函 ...
- 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& ...
- UVA.10305 Ordering Tasks (拓扑排序)
UVA.10305 Ordering Tasks 题意分析 详解请移步 算法学习 拓扑排序(TopSort) 拓扑排序的裸题 基本方法是,indegree表示入度表,vector存后继节点.在tops ...
随机推荐
- zend framework安装中出现的问题与总结
1.按照官方的教程来做http://framework.zend.com/manual/current/en/user-guide/skeleton-application.html 但其中有些步骤没 ...
- 关于QT、GCC、GNU下各个版本的下载地址
http://download.qt.io/ http://ftp.gnu.org/gnu/gcc/ http://ftp.gnu.org/pub/gnu/
- 3D模型选中显示样式改变
osg::ref_ptr<osg::Material> material = new osg::Material(); //模型材质信息 material->setTranspare ...
- IC卡存储器介绍
自从80年代中期出现IC电话卡后,基本已取代了原来流行的电话磁卡,磁卡存在存在严重的安全问题,已逐步淘汰.即使IC电话卡,也不能算很安全,卡内所有数据只要有简单的读写装置并按时序操作都能读取,事实上电 ...
- mybatis.generator.configurationFile
mybatis.generator.configurationFile 有一个更好的配置方法,可以不用在generateConfig.xml里面写死驱动的地址:如果你的mybatis连接也是在pom. ...
- Android 天天爱消除辅助
简介 <天天爱消除>是一款移植于手游的消除类益智游戏,该游戏只有通过手机登录QQ跟微信才能进行,这样一来这款游戏必然会大红大紫. 功能 开发Android自动化触屏事件,录制操作脚本,实现 ...
- Redis用户添加、分页、登录、注册、加关注案例
连接redis代码redis.php <?php //实例化 $redis = new Redis(); //连接服务器 $redis->connect("localhost&q ...
- SDN 编程语言 p4(SDN programming language P4)
行业趋势,SND是未来. P4 是未来. SDN is inevitably, and P4 is inevitably. P4 = Programming Protocol-Independent ...
- js 事件之 createEvent、dispatchEvent
//document上绑定自定义事件ondataavailable document.addEventListener('customevent', function(event) { alert(e ...
- Dot模板的使用小结2
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...