UVa-10905 Children's Game
来源:互联网 发布:2016最新赚钱网络手游 编辑:程序博客网 时间:2024/05/20 06:38
给定n个整数,把他们连接成一个最大的整数,如123,124,56,90连接成9056124123
考虑:先将其进行排序,比如先取两个数啊a,b,若 a+b>b+a 则 把其合成ab的形式再与其他数字用相同的方法进行比较,合成,最后的结果一定是最大的
#include<iostream>#include<algorithm>#include<cstring> using namespace std;bool cmp(string a,string b){return a+b>b+a;//string大小的比较是从第一位字符开始}int main(){int n;while(cin>>n&&n){string a[n];for(int i=0;i<n;i++){cin>>a[i];}sort(a,a+n,cmp);//cmp是比较函数自己编写for(int j=0;j<n;j++){cout<<a[j];}cout<<endl;}return 0;}
0 0
- UVa 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905 - Children's Game
- uva 10905 - Children's Game
- UVA 10905 Children's Game
- UVa 10905 - Children's Game
- Uva-10905-Children’s Game
- UVa 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905 - Children's Game
- UVa 10905 - Children's Game
- uva 10905-Children’s Game
- UVa 10905: Children's Game
- UVA 10905 - Children's Game
- UVA 10905 Children's Game
- UVA 10905 - Children’s Game
- uva 10905 Children's Game
- uva 10905 Children's Game
- 模板初探
- C++ 模板详解(一)
- Kotlin的数据类:节省很多行代码(KAD 10)_0
- tcp/ip详解(17-19)
- 基于知识图谱的电影自动问答系统(二)自动问答实现
- UVa-10905 Children's Game
- SLAM学习资料
- PAT:B1021. 个位数统计 (15)
- android手机的扩容教程,解决手机系统空间不足
- 不带头结点的单链表的常规操作
- VTK修炼之道59:图形基本操作进阶_纹理映射
- UVA1610:Party Games(聚会游戏)
- Tensorflow.org不能访问的处理
- 内部排序之选择排序:简单选择排序,堆排序