任务描述
若干个非负整数,按照不同的顺序组合拼接可以组成不同的整数,比如,有四个数123、124、56和90,可以组成的数是1231245690、1241235690、5612312490、9012312456和9056124123等等,但是,其中最大的就是9056124123。本关任务,编写一个程序把所输入的非负整数,进行拼接组合成一个最大的整数。
输入输出描述
输入 输入文件中包含多个测试数据。输入文件的第1行为一个整数N(0<N<1000),表示测试数据的数目。每个测试数据占一行:首先是一个正整数R(0<R<100),表示该组整数有R个;然后是R个小于65536的非负整数。 输出 对输入文件中的每个测试数据,输出该组整数能组成的最大数。
输入输出样例:
1 4 123 124 56 90
Sample Output
9056124123
#include<algorithm> #include<iostream> #include<math.h> using namespace std; // 请补充代码,完成本关任务 int i,j,k,n,r; string ma,x; string a[10000]; bool order(string a,string b){ return a+b>b+a; } int main() { cin>>n; while(n--){ cin>>r; for(int i=0;i<r;i++)cin>>a[i]; sort(a, a + r,order); for(int i=0;i<r;i++) cout<<a[i]; cout<<endl; } }