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

#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. 将Opencv java中的Mat通过jni传递到C++中的方法

    public native void FindFeatures(long matAddrGr, long matAddrRgba); ... mRgba = new Mat(height, width ...

  2. JQuery EasyUI validate 扩展

    validate 扩展js $.extend($.fn.validatebox.defaults.rules, { equals: { validator: function(value,param) ...

  3. VisualStudio2017中新建的ASP.NET Core项目中的各个文件的含义

     Program.cs is the entry point for the web application; everything starts from here. As we mentione ...

  4. yii2之目录解析

    /backend 1.assets\AppAsset.php2.config\main-local.php 注释14到17行3.controllers\SiteController -> act ...

  5. hdu1520 Anniversary party

    Anniversary party HDU - 1520 题意:你要举行一个晚会,所有人的关系可以构成一棵树,要求上下级关系的人不能同时出现,每一个人都有一个rating值,要求使整个晚会的ratin ...

  6. 洛谷P1368 均分纸牌(加强版)

    P1368 均分纸牌(加强版) 题目描述 有 N 堆纸牌,编号分别为 1,2,…, N.每堆上有若干张,纸牌总数必为 N 的倍数.可以在任一堆上取1张纸牌,然后移动. 移牌规则为:在编号为 1 堆上取 ...

  7. Hadoop安装包下载方法

    Hadoop3.0版本的诞生,引入了很多新功能,为了验证Hadoop2.0与3.0版本的性能,需下载Hadoop的不同版本.故下文演示如何下载Hadoop安装包的方法. 1. 进入Apache Had ...

  8. Java:创建线程

    Java定义了两种创建线程的方法: 1.实现Runnable接口 要实现Runnable接口,只需简单地实现run()方法即可,声明如下:public void run() 在run()方法中,可以定 ...

  9. CC14:集合栈

    题目 请实现一种数据结构SetOfStacks,由多个栈组成,其中每个栈的大小为size,当前一个栈填满时,新建一个栈.该数据结构应支持与普通栈相同的push和pop操作. 给定一个操作序列int[] ...

  10. Codeforces Round #561 (Div. 2) A. Silent Classroom

    链接:https://codeforces.com/contest/1166/problem/A 题意: There are nn students in the first grade of Nlo ...