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 ...
随机推荐
- AlertDialog基本用法详解
AlertDialog简单介绍: AlertDialog可以在当前活动界面弹出一个对话框,用于提示一些重要信息或是警告内容. AlertDialog置于所有页面元素之上,能够屏蔽其他控件的交互. 由于 ...
- 低功耗之战!ANT VS Bluetooth LE
利用近距离无线通信技术将手机及可穿戴式传感器终端等与智能电话连接起来,实现新的功能.最近,以此为目标的行动正在展开.其中备受关注的近距离无线方式是“ANT”和“Bluetooth LE”.为了在各种便 ...
- WinSetupFromUSB – Install Windows XP from USB Flash Drive
http://myeeeguides.wordpress.com/2008/11/15/winsetupfromusb-install-windows-xp-from-usb-flash-drive/ ...
- QCA4002/QCA4004 为主流家电和消费电子产品推出低功耗Wi-Fi平台
美国高通公司日前宣布,其子公司高通创锐讯推出全新芯片系列,这是低功耗Wi-Fi解决方案系列的一部分,可连接组成物联网的各种设备.QCA4002和QCA4004网络平台在芯片上纳入IP堆栈及完整的网络服 ...
- 数组Magic Index
Question A magic index in an array A[1...n-1] is defined to be an index such that A[i] = i. Given a ...
- C语言入门(5)——运算符与表达式
C语言中运算符和表达式数量之多,在高级语言中是少见的.正是丰富的运算符和表达式使C语言功能十分完善.这也是C语言的主要特点之一. C语言的表达式由运算符.常量及变量构成.C语言表达式基本遵循一般代数规 ...
- Windows Azure 社区新闻综述(#71 版)
欢迎查看最新版本的每周综述,其中包含有关云计算和 Windows Azure的社区推动新闻.内容和对话. 以下是过去一周基于您的反馈汇集在一起的内容: 文章.视频和博客文章 · 使用 Azure ...
- Android采用HttpClient下载图片
在上一章中谈到Android采用HttpURLConnection下载图片,本章使用HttpClient下载图片 HttpURLConnection与HttpClient的差别: HttpClient ...
- English - 英语中的时间表达法,这里全啦!
- Linux远程自动输入密码抓取远程资源
#!/usr/bin/expect -fset timeout 3000set sys_date [lindex $argv 0] #要抓取的文件日期spawn scp /data3/xiaorui/ ...