题目: 小组中每位都有一张卡片卡片上是6位内的正整数;将卡片连起来可以组成多种数字;计算组成的最大数字。
输入4589,101,41425,9999,输出9999458941425101,题目极限是需要对25个6位数进行拼接。时间限制1s 空间限制64MB;
思路,将字段两两比较,大的往前移动
代码
public class 最大数组(){ public static void main(String[] args){ Scanner sc =new Scanner(System.in); String [] str=sc.nextLine().split(","); int len=str.length; for(int i=0,i<len,i++){ for(int j=i+1,i<len,j++){ if(Integer.parseInt(str[i]+str[j])<Integer.parseInt(str[j]+str[i])){ String temt=str[i]; str[i]=str[j]; str[i]=temp; } } } String res=""; for(int i=0,i<len,i++){ res+=str[i] } Syste.out,printInt(res); } }