코딩테스트/SW Expert
[SWEA] 7991. 줄 세우기
jhk828
2021. 2. 21. 23:56
[SWEA] 7991. 줄 세우기
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
배열의 중간 위치에 원소를 삽입하는 경우가 많기 때문에 LinkedList를 이용하여 풀었다.
import java.io.*;
import java.util.*;
// 210221
public class Main_BJ_2605_줄세우기 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
LinkedList<Integer> list = new LinkedList<>();
list.add(sc.nextInt(), 1);
if (N > 0) {
for(int i=2; i<=N; i++) {
list.add(sc.nextInt(), i);
}
}
for(int i=N-1; i>=0; i--) {
System.out.print(list.get(i) + " ");
}
sc.close();
}
}