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

  • 相关阅读:
    【Ionic+AngularJS 开发】之『个人日常管理』App(一)
    [热拔插] 轻量级Winform插件式框架
    Electron开发
    Cordova+Ionic之坑
    Unity学习笔记
    【树结构数据同步】公司部门—通讯录数据同步
    java enum用法
    Java中哈希表(Hashtable)是如何实现的
    注意for循环中变量的作用域
    BI-日期维度表-SQL SERVER
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3488334.html
Copyright © 2011-2022 走看看