-
[알고리즘-JAVA] 백준 알고리즘 2751번 - 수 정렬하기 2알고리즘 2019. 8. 7. 19:02
접근 과정
1. 어떤 문제로 이해 했는가? 그리고 문제의 제약 조건은?입력받은 인풋들을 오름차순으로 정렬하는 문제.
2. 나의 방식대로 문제를 재정의 하자..
3. 어떤 알고리즘과 자료구조를 사용할 것인가?ArrayList, Sort 함수
4. 어떻게 계산할 것인가?
1) 입력BufferedReader, InputStreamReader를 이용
2) 시간 복잡도 계산
sort함수의 복잡도. NlogN으로 예상.
5. 주의할 점은 무엇인가?.
6. 풀이 과정
java.util.Collections, java.util.ArrayList를 이용해
sort했다.
[전체 소스 코드]
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Collections; import java.util.ArrayList; public class Main { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int inputcount = Integer.parseInt(br.readLine()); ArrayList<Integer> arr = new ArrayList<Integer>(); for (int i = 0; i < inputcount; i++){ arr.add(Integer.parseInt(br.readLine())); } Collections.sort(arr); for (int i = 0; i < arr.size(); i++){ System.out.println(arr.get(i)); } } }
'알고리즘' 카테고리의 다른 글
[알고리즘-JAVA] 백준 알고리즘 1991번 - 트리의 순회[미완] (0) 2019.08.11 [알고리즘-JAVA] 백준 알고리즘 11724번 - 연결 요소의 개수 (0) 2019.08.08 [알고리즘-JAVA] 백준 알고리즘 2745번 - 진법 변환 (0) 2019.08.07 [알고리즘-JAVA] 백준 알고리즘 11005번 - 진법 변환2 (0) 2019.08.07 [알고리즘-JAVA] 백준 알고리즘 1934번 - 최소공배수 (0) 2019.08.07