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 ...
随机推荐
- RelativeLayout布局下实现控件平分空间
起源:使用惯LinearLayout的朋友都知道,若想实现对屏幕的等分,只需要设置Layout_weight的值即可. 可是在RelativeLayout布局下实现等分却不是那么容易. 下面就简单介绍 ...
- ASP.NET 连接 SQL Server 和 Oracle 教程
临近期末,有很多同学都问我怎么关于ASP.NET 连接 SQL Server 和 Oracle 的问题.由于人太多了,我也不能一一去帮忙,就写了这篇博客.希望对大家有用处. 首先,前期准备是要安装数据 ...
- startup_LPC17XX.s 启动文件分析
工程中startup_LPC17XX.s是M3的启动文件,启动文件由汇编语言写的,它的作用一般是下面这几个: 1)堆和栈的初始化 2)中断向量表定义 3)地址重映射及中断向量表的转移 4)设置系统时钟 ...
- paip.提升用户体验---论文本编辑器的色彩方案
paip.提升用户体验---论文本编辑器的色彩方案 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.ne ...
- [LeetCode] Search a 2D Matrix [25]
题目 Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the fo ...
- SET ANSI_NULLS (Transact-SQL)
指定在 SQL Server 2014 中与 Null 值一起使用等于 (=) 和不等于 (<>) 比较运算符时采用符合 ISO 标准的行为. 当 SET ANSI_NULLS 为 ON ...
- PHP删除HTMl标签
/** * 取出html标签 * * @access public * @param string str * @return string * */ function deletehtml($str ...
- OO真经——关于面向对象的哲学体系及科学体系的探讨(下)
真经第六章——运作 Moving “运动是绝对的——牛顿” 6.1.导言 在前五章中,我们从世界观的这话题开始,逐步引出了抽象.层次.继承和耦合.这些内容,形成了对象论中关于世界的结构体系. ...
- 笔记-linux下Qt5.3.2 静态编译
这里主要讲linux下的编译,windows下面比较简单 参考:http://qt-project.org/wiki/Building-Qt-5-from-Git 依赖 sudo apt-get in ...
- C#学习日志 day 2 ------ 控制台颜色以及windowsphone 窗体应用试建
成功跑起来了hello之后,试试改变背景颜色.