[softeer] GPT식 숫자 비교
in Algorithm on Algorithm
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
List<String> l = new ArrayList<>();
for(int i = 0 ; i < N ; i++){
l.add(sc.next());
}
Collections.sort(l,(o1,o2) -> {
int nb1_1 = 0;
int nb1_2 = -1;
if(o1.contains(".")){
String[] temp = o1.split("\\.");
nb1_1 = Integer.parseInt(temp[0]);
nb1_2 = Integer.parseInt(temp[1]);
}else nb1_1 = Integer.parseInt(o1);
int nb2_1 = 0;
int nb2_2 = -1;
if(o2.contains(".")){
String[] temp = o2.split("\\.");
nb2_1 = Integer.parseInt(temp[0]);
nb2_2 = Integer.parseInt(temp[1]);
}else nb2_1 = Integer.parseInt(o2);
if(nb1_1 != nb2_1){
return nb1_1 - nb2_1;
}else{
return nb1_2 - nb2_2;
}
});
for(String s : l) System.out.println(s);
}
}