20170811

/*
设有n个正整数,将他们连接成一排,组成一个最大的多位整数。
如:n=3时,3个整数13,312,343,连成的最大整数为34331213。
如:n=4时,4个整数7,13,4,246连接成的最大整数为7424613。
*/

//在线编程v1.0

//#include <iostream>
//#include <vector>
//#include <math.h>
//#include <stdio.h>
//
//#pragma warning(disable:4996)
//
//using namespace std;
//
//void Swap(int &a, int &b)
//{
//    int temp = a;
//    a = b;
//    b = temp;
//}
//
//int main()
//{
//    int N;
//    int TempVarable;
//
//    cin >> N;
//    vector <int> SaveInputData(N);
//    vector <int> SaveBitData(N);
//
//    for (int i = 0; i < N; ++i)
//    {
//        scanf("%d", &TempVarable);
//        //SaveInputData.push_back(TempVarable);
//        SaveInputData[i] = TempVarable;
//    }
//
//    //判断几位数并且将个位数都存放在一个新的数组
//    for (int i = 0; i < N; ++i)
//    {
//        if (SaveInputData[i] / 10 == 0) //1
//            SaveBitData[i] = SaveInputData[i];
//        else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10))  //2
//        {
//            SaveBitData[i] = (SaveInputData[i] / 10);
//        }
//
//        else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100)) //3
//        {
//            SaveBitData[i] = (SaveInputData[i] / 100);
//            
//        }
//    }
//    //从大到小排序
//    for (int i = 0; i < N; ++i)
//        for (int j = 0; j < N - 1 - i; ++j)
//        {
//            if (SaveBitData[j] < SaveBitData[j + 1])
//                Swap(SaveBitData[j], SaveBitData[j + 1]);
///*            if (SaveBitData[j] == SaveBitData[j + 1])
//            {
//                if (SaveInputData[j] / 10 < SaveInputData[j + 1] / 10)
//                    Swap(SaveBitData[j], SaveBitData[j + 1]);
//            } */       
//        }
//
//    //还原成原数
//    for (int i = 0; i < N; ++i)
//    {
//        if (SaveInputData[i] / 10 == 0)  //1位数
//        {
//            for (int j = 0; j < N; ++j)
//            {
//                if (SaveInputData[i] % 10 == SaveBitData[j])
//                {
//                    SaveBitData[j] = SaveInputData[i];
//                }
//            }
//
//        }
//        else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10))//2位数
//        {
//            for (int j = 0; j < N; ++j)
//            {
//                if (SaveInputData[i] / 10 == SaveBitData[j])
//                {
//                    SaveBitData[j] = SaveInputData[i];
//                }
//            }
//        }
//
//        else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100))//3位数
//        {
//            for (int j = 0; j < N; ++j)
//            {
//                if (SaveInputData[i] / 100 == SaveBitData[j])
//                {
//                    SaveBitData[j] = SaveInputData[i];
//                }
//            }
//        }
//    }
//
//    //连接成一个数
//    long long int MaxResult = 0;
//    int OldCount = 0;
//    int a = 0;
//    for (int i = N - 1; i >= 0; i--)
//    {
//        int Count = 0;
//        a = SaveBitData[i];
//        if (SaveBitData[i] < 10)
//        {
//            Count++;
//        }
//        while (SaveBitData[i] >= 10)
//        {
//            Count++;
//            SaveBitData[i] = SaveBitData[i] / 10;
//        }
//
//        OldCount += Count;
//        
//        if (i == N-1)
//            MaxResult = a;
//        else
//        {
//            MaxResult += a * pow(10, OldCount);
//        }
//    } 
//    cout << MaxResult;
//    system("pause");
//}
//
//
//

//在线编程v2.0

//#include <iostream>
//#include <vector>
//#include <math.h>
//#include <stdio.h>
//
//#pragma warning(disable:4996)
//
//using namespace std;
//
//void Swap(int &a, int &b)
//{
//    int temp = a;
//    a = b;
//    b = temp;
//}
//
//int main()
//{
//    int N;
//    int TempVarable;
//
//    cin >> N;
//    vector <int> SaveInputData(N);
//    vector <int> SaveBitData(N);
//
//    for (int i = 0; i < N; ++i)
//    {
//        scanf("%d", &TempVarable);
//        //SaveInputData.push_back(TempVarable);
//        SaveInputData[i] = TempVarable;
//    }
//
//    //判断几位数并且将个位数都存放在一个新的数组
//    for (int i = 0; i < N; ++i)
//    {
//        if (SaveInputData[i] / 10 == 0) //1
//            SaveBitData[i] = SaveInputData[i];
//        else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10))  //2
//        {
//            SaveBitData[i] = (SaveInputData[i] / 10);
//        }
//
//        else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100)) //3
//        {
//            SaveBitData[i] = (SaveInputData[i] / 100);
//
//        }
//    }
//    //从大到小排序
//    for (int i = 0; i < N; ++i)
//        for (int j = 0; j < N - 1 - i; ++j)
//        {
//            if (SaveBitData[j] < SaveBitData[j + 1]) //首位数字不同排序
//            {
//                Swap(SaveBitData[j], SaveBitData[j + 1]);
//                Swap(SaveInputData[j], SaveInputData[j + 1]);
//            }
//            if (SaveBitData[j] == SaveBitData[j + 1]) //首位数字相同
//            {
//                if (SaveInputData[j] / 10 < SaveInputData[j + 1] / 10)
//                {
//                    Swap(SaveInputData[j], SaveInputData[j + 1]);
//                    
//                }
//                if (SaveInputData[j] / 10 == SaveInputData[j + 1] / 10)
//                {
//                    if (SaveInputData[j] < SaveInputData[j + 1])
//                    {
//                        Swap(SaveInputData[j], SaveInputData[j + 1]);
//                    }
//                }
//
//            } 
//        }
//
//    //还原成原数
//     for (int i = 0; i < N; ++i)
//    {
//        if (SaveInputData[i] / 10 == 0)  //1位数
//        {
//            for (int j = 0; j < N; ++j)
//            {
//                if (SaveInputData[i] % 10 == SaveBitData[j])
//                {
//                    SaveBitData[j] = SaveInputData[i];
//                }
//            }
//
//        }
//        else if ((SaveInputData[i] / 10 >= 0) && (SaveInputData[i] / 10 < 10))//2位数
//        {
//            for (int j = 0; j < N; ++j)
//            {
//                if (SaveInputData[i] / 10 == SaveBitData[j])
//                {
//                    SaveBitData[j] = SaveInputData[i];
//                }
//            }
//        }
//
//        else if ((SaveInputData[i] / 10 >= 10) && (SaveInputData[i] / 10 < 100))//3位数
//        {
//            for (int j = 0; j < N; ++j)
//            {
//                if (SaveInputData[i] / 100 == SaveBitData[j])
//                {
//                    SaveBitData[j] = SaveInputData[i];
//                }
//            }
//        }
//    }
//
//    //连接成一个数
//    long long int MaxResult = 0;
//    int OldCount = 0;
//    int a = 0;
//    for (int i = N - 1; i >= 0; i--)
//    {
//        int Count = 0;
//        a = SaveBitData[i];
//        if (SaveBitData[i] < 10)
//        {
//            Count++;
//        }
//        while (SaveBitData[i] >= 10)
//        {
//            Count++;
//            SaveBitData[i] = SaveBitData[i] / 10;
//        }
//
//        OldCount += Count;
//
//        if (i == N - 1)
//            MaxResult = a;
//        else
//        {
//            MaxResult += a * pow(10, OldCount);
//        }
//    }
//    cout << MaxResult;
//    system("pause");
//}

//在线编程 sort v3.0

//#include <iostream>    
//#include <string>    
//#include <vector>    
//#include <algorithm>        
//using namespace std;        
//int CompreFunction( string str1, string str2)//str1>str2 返回1 否则返回 0    
//{    
//    string nstr1 = str1 + str2 ;    
//    string nstr2 = str2 + str1 ;            
//    return nstr1>nstr2;         //return (nstr1>nstr2)?1:0;
//}        
//int main()    
//{    
//     int Number = 0 ;    
//     cin >> Number;
//     string tmp ;    
//     vector<string> vstr ;  
//
//     for (int i = 0; i < Number; ++i)
//     {    
//          cin>>tmp ;    
//          vstr.push_back(tmp);    
//     }    
//     sort(vstr.begin(), vstr.end(), CompreFunction);
//     for (auto c : vstr) 
//         cout << c;                   /*     for (int i = 0; i < Number; ++i)
//                                                  cout << vstr[i];  */ 
//     cout<<endl;        
//     return 0;    
//}


//lambda函数
#include <string>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<string> sArray;
    for (int i = 0; i<n; i++) {
        string temp;
        cin >> temp;
        sArray.push_back(temp);
    }
    sort(sArray.begin(), sArray.end(), [](string s1, string s2){
        return (s1 + s2) >(s2 + s1);
    });
    for (auto s : sArray) {
        cout << s;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值