---
title: "2163:大合照"
author: "hefeijack"
date: "2013-10-02T22:52:36Z"
tags: []
categories: ["非技术"]
slug: "2163"
draft: false
lastmod: "2013-10-02T22:52:36Z"
id: 1950153
url: "https://hefeijack.iteye.com/blog/1950153"
---

### 题目描述

 

ACM俱乐部要照大合照了！

"顺序怎么排？"

"按会员编号吗？"

"我们可是学计算机考研的人唉！"

"那么还是以会员编号为依据吧。但是不是单纯按编号大小排列，而是让这些编号连在一起之后组成的那个整数最小。"

 

 

### 输入格式

 

输入有多组数据。

每组数据两行。

第一行包含一个正整数n（小于等于10000），代表会员人数。

第二行包含n个正整数（小于等于10000000），代表各会员的编号，编号可能有相同。

 

 

### 输出

 

对应每组数据，输出一个正整数，这些会员编号连接成的最小的整数。

 

 

### 样例输入

7  
14 36 154 58 36 3 8  
9  
5534 5226 5636 99956 30 135 35 8 77

### 样例输出

1415433636588  
135303552265534563677899956

 

 

```
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

int n;
char str[11000][40];

int compare(const void* x, const void* y){
    char a[40],b[40];
    strcpy(a, *(const char**)x);
    strcat(a, *(const char**)y);
    strcpy(b, *(const char**)y);
    strcat(b, *(const char**)x);
    return strcmp(a, b);
}

void PrintMinNumber(int* numbers)
{

    char** str = (char**)(new int[n]);
    //char str[11000][40];
    for(int i = 0; i < n; ++i)
    {
        str[i] = new char[40];
        sprintf(str[i], "%d", numbers[i]);
    }
    //printf("2222\n");
    // Sort all strings according to algorithm in function compare
    qsort(str, n, sizeof(char*), compare);
    //printf("3333\n");
    for(int i = 0; i < n; ++i)
        printf("%s", str[i]);
    printf("\n");

}



int main(){
    
    //freopen("input.txt","r",stdin);

    int a[99999];
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        PrintMinNumber(a);
    }
    return 0;
}
```