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

  • 相关阅读:
    Kubernetes部署高可用MongoDB集群
    C博客作业00—我的第一篇博客
    小发现,关于windows窗口中的F10快捷键
    C#小程序——从百度摘取搜索结果。
    elasticsearch 基础语句
    html嵌套html解决办法(<object></object>)
    websocket 前后台代码实例
    css3轮播图实现代码
    validate使用案例
    SiteMap Editor for Microsoft Dynamics CRM 2011
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3488334.html
Copyright © 2011-2022 走看看