티스토리 뷰
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(in.readLine());
int[] array = new int[count];
for(int i=0; i<count; ++i) {
array[i] = Integer.parseInt(in.readLine());
}
Arrays.sort(array);
for(int i: array) {
System.out.println(i);
}
}
}
Java의 Arrays.sort()나 Collections.sort() 같은 언어에서 구현된 메소드로 정렬하는 것이 편하다.
Swift에서도 sort()를 써서 채점을 해봤으나 시간 초과...
let count = Int(readLine()!)!
var array = [Int]()
for _ in 0..<count {
array.append(Int(readLine()!)!)
}
array.sort(by: <)
for i in array {
print(i)
}
'Algorithm > Baekjoon Online Judge' 카테고리의 다른 글
11651번 '좌표 정렬하기 2' (0) | 2018.08.05 |
---|---|
11650번 '좌표 정렬하기' (0) | 2018.08.05 |
2004번 '조합 0의 개수' (0) | 2018.08.01 |
1676번 '팩토리얼 0의 개수' (0) | 2018.08.01 |
10872번 '팩토리얼' (0) | 2018.08.01 |
댓글