题解 | #拼数#
拼数
https://ac.nowcoder.com/acm/problem/16783
import java.util.Scanner;
public class Main {
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
String []strArray = sc.nextLine().split(" ");
for(int k = 0;k<n;k++){
for(int m = 0;m<n-1-k;m++){
if(!sort1(strArray[m], strArray[m+1])){
String temp = strArray[m];
strArray[m] = strArray[m+1];
strArray[m+1] = temp;
}
}
}
for(int i = 0;i<n;i++) System.out.print(strArray[i]);
}
public static boolean sort1(String str1,String str2){
char []char1 = (str1+str2).toCharArray();
char []char2 = (str2+str1).toCharArray();
for(int i = 0;i<char1.length;i++){
if(char1[i]>char2[i]) return true;
else if(char1[i]<char2[i]) return false;
}
return false;
}
}
注意得用String类型,用int会超。