LinkedList를 이용해서 간단하게 풀었다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.*; | |
/** | |
* BOJ 2605 줄 세우기 | |
* https://gist.github.com/KSH-code/5d0af23c0bd3317ce83254be13a672f9 | |
*/ | |
public class Main{ | |
public static void main(String[] args) throws IOException{ | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); | |
int N = Integer.parseInt(br.readLine()); | |
LinkedList<Integer> linkedList = new LinkedList<>(); | |
linkedList.add(1); | |
String str1[] = br.readLine().split(" "); | |
for(int i = 2; i<=N; i++){ | |
linkedList.add(linkedList.size() - Integer.parseInt(str1[i - 1]), i); | |
} | |
for(int i = 0; i<N; i++){ | |
bw.write(linkedList.get(i) + " "); | |
} | |
bw.flush(); | |
} | |
} |
'IT > 알고리즘' 카테고리의 다른 글
BOJ 14852 타일채우기 3 풀이 (0) | 2017.10.18 |
---|---|
BOJ 2309 일곱난쟁이 풀이 (0) | 2017.10.18 |
BOJ 11404 플로이드 Floyd-Warshall (0) | 2017.10.18 |
BOJ 1717 집합의 표현 disjoint-set (0) | 2017.10.17 |
BOJ 1753 최단경로 다익스트라 알고리즘 (Dijkstra) (0) | 2017.10.17 |