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

  • 相关阅读:
    同一子网建立ssh通道,映射到本地
    机器学习线性模型-自定义各个模块阶段
    MATLAB中图像处理的函数
    基于鱼皮肤的鱼个体识别(1)
    防骗指南-东南亚绑架,诈骗,菠菜
    防骗指南-识别传销
    防骗指南-套路贷以及肉偿
    防骗指南-套路贷如何识别
    Opencv 特征提取与检测-Haar特征
    1. QCamera2基础组件——cam_semaphore
  • 原文地址:https://www.cnblogs.com/doubleshik/p/3488334.html
Copyright © 2011-2022 走看看