文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition) AtCoder - 1978

文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)

 AtCoder - 1978 

Problem Statement

 

Iroha has a sequence of N strings S1,S2,…,SN. The length of each string is L.

She will concatenate all of the strings in some order, to produce a long string.

Among all strings that she can produce in this way, find the lexicographically smallest one.

Here, a string s=s1s2s3...sn is lexicographically smaller than another string t=t1t2t3...tm if and only if one of the following holds:

  • There exists an index i(1≦imin(n,m)), such that sj=tj for all indices j(1≦j<i), and si<ti.
  • si=ti for all integers i(1≦imin(n,m)), and n<m.

 

Constraints

 

  • 1≦N,L≦100
  • For each i, the length of Si equals L.
  • For each iSi consists of lowercase letters.

Input

 

The input is given from Standard Input in the following format:

N L
S1
S2
:
SN

Output

 

Print the lexicographically smallest string that Iroha can produce.

Sample Input 1

 

3 3
dxx
axx
cxx

Sample Output 1

 

axxcxxdxx

The following order should be used: axxcxxdxx.

 

#include
#include
#include
#include<string>
#include
#include
#include
#include<set>
#include
#include
#include
#include
#define maxn 1010
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
#define E 1e-8
#define mod 1000000007
#define P pair
using namespace std;
//n个  长度是L
int main()
{
    int n,l;
    while(cin>>n>>l)
    {
        string s[105];
        int a[105];
        for(int i = 0 ; i < n ; i++ )
        {
            cin>>s[i];
            a[i] = (int)s[i][0];
            //cout<
        }
        sort(s+0,s+n);
        for(int j = 0 ; j < n ; j++ )
        cout<<s[j];
        }
}

 

转载于:https://www.cnblogs.com/upstart/p/8982412.html

你可能感兴趣的:(文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition) AtCoder - 1978)