#16692: JAVA


ml0427 (ml0427)

學校 : 不指定學校
編號 : 82063
來源 : [1.34.207.68]
最後登入時間 :
2023-07-20 16:51:16
a225. 明明愛排列 | From: [218.161.78.2] | 發表日期 : 2019-01-30 14:46

package test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;

/**
*
*
* @author michael
*/
public class Test {

public static void main(String[] args) throws IOException {

BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
String text;

while (!((text = buf.readLine()) == null || "".equals(text))) {
int number = Integer.parseInt(text);

text = buf.readLine();
String[] in = text.split(" ");
Arrays.sort(in, new Comparator<String>() {

@Override
public int compare(String o1, String o2) {
long a = Integer.parseInt(o1);
long b = Integer.parseInt(o2);
Long ans;

ans = a % 10 - b % 10;
if (ans != 0) {
return ans.intValue();
}
ans = b - a ;
if (ans != 0) {
return ans.intValue();
}

return 0;
}
});
for (String string : in) {
System.out.print(string + " ");
}
System.out.println();
}
}

}

 
ZeroJudge Forum