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

  • 相关阅读:
    pytest学习Pytest基础
    Docker基础认识
    DNS 域名解析协议
    Python从数据库取数据到Excel
    PO设计模式
    unittest多种加载执行用例方法
    Dev XtraGridView 添加行时滚动条(界面)随焦点滚动
    阅读器关闭时READ的尝试无效 真正原因 测试通过解决办法
    转帖 用SQL语句 查看 某一存储过程 所带参数
    转 C#多线程及控制线程数量,对for循环输出效率
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3488334.html
Copyright © 2011-2022 走看看