zoukankan      html  css  js  c++  java
  • uva10905

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <string>
     4 using namespace std;
     5 
     6 bool cmp(string a,string b)
     7 {
     8     return a+b>b+a;
     9 }
    10 
    11 void solve(int n)
    12 {
    13     string a[100];
    14     for(int i=0;i<n;i++)
    15     {
    16         cin>>a[i];
    17     }
    18 
    19     sort(a,a+n,cmp);
    20     for(int i=0;i<n;i++)
    21         cout<<a[i];
    22     cout<<endl;
    23 
    24 
    25 }
    26 
    27 
    28 int main()
    29 {
    30     int n;
    31     while(cin>>n && n)
    32     {
    33         solve(n);
    34     }
    35 
    36 }

    题目大意就是给出一些数字问怎么拼接最大, 注意类似  90, 9  这样子最大是990;

    可以用string的字符串相加进行比较

    题目:

    4th IIUCInter-University Programming Contest, 2005

    A

    Children’s Game

    Input: standard input
    Output: standard output

    Problemsetter: Md. Kamruzzaman

    There are lots of number games for children. These games are pretty easy to play but not so easy to make. We will discuss about an interesting game here. Each player will be given N positive integer. (S)He can make a big integer by appending those integers after one another. Such as if there are 4 integers as 123, 124, 56, 90 then the following integers can be made – 1231245690, 1241235690, 5612312490, 9012312456, 9056124123 etc. In fact 24 such integers can be made. But one thing is sure that 9056124123 is the largest possible integer which can be made.

    You may think that it’s very easy to find out the answer but will it be easy for a child who has just got the idea of number?

    Input

    Each input starts with a positive integer N (≤ 50). In next lines there are N positive integers. Input is terminated by N = 0, which should not be processed.

    Output

    For each input set, you have to print the largest possible integer which can be made by appending all the N integers.

    Sample Input

    Output for Sample Input

    4
    123 124 56 90
    5
    123 124 56 90 9
    5
    9 9 9 9 9
    0

    9056124123
    99056124123
    99999

  • 相关阅读:
    Droptiles
    10 条建议让你创建更好的 jQuery 插件
    15个值得开发人员关注的jQuery开发技巧和心得
    8 个最好的 jQuery 树形 Tree 插件
    jQuery的发展史,你知道吗?
    20+个可重复使用的jQuery代码片段
    10 款基于 jQuery 的切换效果插件推荐
    关于浏览器事件的思考
    JS实现复制到剪贴板(兼容FF/Chrome/Safari所有浏览器)
    Javascript函数声明与函数表达式的区别
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3488334.html
Copyright © 2011-2022 走看看