贪心,假如任意给出一个序列,如果两两交换了以后会变大,那么就交换,直到不能交换为止。

#include<bits/stdc++.h>
using namespace std;
const int maxn = ; string s[maxn];
int rk[maxn];
bool cmp(int x,int y)
{
int i = , j = , n1 = s[x].size(), n2 = s[y].size();
string *s1 = &s[x], *s2 = &s[y];
int ct = n1+n2;
while(ct--){
if(i == n1) i = ,s1 = &s[y];
if(j == n2) j = ,s2 = &s[x];
if(s1->at(i) != s2->at(j)) return s1->at(i) < s2->at(j);
i++;j++;
}
return false;
} int main()
{
//freopen("in.txt","r",stdin);
ios_base::sync_with_stdio(false);
int n;
while(cin>>n&&n){
for(int i = ; i < n; i++) cin>>s[i], rk[i] = i;
sort(rk,rk+n,cmp);
for(int i = n-; i>=; i--) printf("%s",s[rk[i]].c_str());
puts("");
}
return ;
}

UVA 10905 Children's Game (贪心)的更多相关文章

  1. UVA 10905 Children's Game (贪心)

    Children's Game Problem Description There are lots of number games for children. These games are pre ...

  2. UVA 10905 Children's Game 孩子的游戏 贪心

    题意:给出N个数,要求把它们拼凑起来,让得到的数值是最大的. 只要分别比较两个数放前与放后的值的大小,排序后输出就可以了. 比如123和56,就比较12356和56123的大小就行了. 写一个比较函数 ...

  3. uva 10905 Children's Game (排序)

    题目连接:uva 10905 Children's Game 题目大意:给出n个数字, 找出一个序列,使得连续的数字组成的数值最大. 解题思路:排序,很容易想到将数值大的放在前面,数值小的放在后面.可 ...

  4. UVa 10905 - Children's Game(求多个正整数排列后,所得的新的数字的极值)

    4thIIUCInter-University Programming Contest, 2005 A Children’s Game Input: standard input Output: st ...

  5. 【字符串排序,技巧!】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 ...

  6. UVa 10905 - Children's Game 排序,题目没有说输入是int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  7. UVa 10905 Children's Game

    注意!这不是单纯的字典序排序,比如90.9,应该是990最大 对字符串排序蛋疼了好久,因为别人说string很慢,所以一直没有用过. 看别人用string还是比较方便的,学习一下 对了,这里的cmp函 ...

  8. Children's Game UVA - 10905

    看90,956这样的串,在比较完之前,就确定大小的,必定选大的放在前.而x=98,y=980;这样的,比较x+y和y+x的大小.如果x+y更小,y就放前. #include <iostream& ...

  9. 【NOIP合并果子】uva 10954 add all【贪心】——yhx

    Yup!! The problem name reects your task; just add a set of numbers. But you may feel yourselvesconde ...

随机推荐

  1. JAVA学习笔记——(五)

    今日内容介绍 1.方法基础知识 2.方法高级内容 3.方法案例 01方法的概述 * A: 为什么要有方法 * 提高代码的复用性 * B: 什么是方法 * 完成特定功能的代码块. 02方法的定义格式 * ...

  2. NOIP2015提高组 跳石头 ACM-ICPC2017香港 E(选择/移除+二分答案)

    跳石头 题目背景 一年一度的“跳石头”比赛又要开始了! 题目描述 这项比赛将在一条笔直的河道中进行,河道中分布着一些巨大岩石.组委会已经选择好了两块岩石作为比赛起点和终点.在起点和终点之间,有 NN  ...

  3. POJ 1845-Sumdiv(快速幂取模+整数唯一分解定理+约数和公式+同余模公式)

    Sumdiv Time Limit:1000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  4. 【异步编程】Part1:await&async语法糖让异步编程如鱼得水

    前导 Asynchronous programming Model(APM)异步编程模型以BeginMethod(...) 和 EndMethod(...)结对出现. IAsyncResult Beg ...

  5. tar,jar和war都是什么

    jar 即Java Archive,java的类进行编译生成的class文件,通常是开发时要引用通用类,打成包便于存放管理. 但如果直接发布这些class文件的话会很不方便,所以就把许多的class文 ...

  6. linux 01 基础命令

    linux 01 基础命令 对于Linux要记住一个概念,一切皆文件,哪怕是目录,也是一个文件 1.修改用户密码 sudo passwd pyvip@Vip:~$ #pyvip表示用户名, Vip表示 ...

  7. Hive_Hive的数据模型_分区表

    Hive的数据模型之分区表 准备数据表: create table sampledata (sid int, sname string, gender string, language int, ma ...

  8. 线程池(4)Executors.newScheduledThreadPool-只执行1次

    例子1:延迟3秒后,只执行1次 ScheduledExecutorService es = Executors.newScheduledThreadPool(5); log.info("开始 ...

  9. 在写fegin客户端的时候无法继承接口

    仔细查看fegin是不是写成类了,要接口才行

  10. 时间日期相关:Date类、DateFormat类、Calendar类

    1 Date类 类 Date 表示特定的瞬间,精确到毫秒. 1秒=1000毫秒 毫秒的0点:公元1970年 一月一日,午夜0:00:00 对应的毫秒值就是0 时间和日期的计算,必须依赖毫秒值. Sys ...