We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
참고: 블로그
package main.java.com.poogle.BOJ.Q17298; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Stack; 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()); int[] answer = new int[n]; int[] arr = new int[n]; Stack<Integer> stack = new Stack<>(); String[] tmp = br.readLine().split(" "); for (int i = 0; i < n; i++) { arr[i] = Integer.parseInt(tmp[i]); } stack.push(0); for (int i = 1; i < n; i++) { if (stack.isEmpty()) { stack.push(i); } while (!stack.isEmpty() && arr[stack.peek()] < arr[i]) { answer[stack.pop()] = arr[i]; } stack.push(i); } while (!stack.isEmpty()) { answer[stack.pop()] = -1; } for (int i : answer) { bw.write(i + " "); } bw.write("\n"); bw.flush(); } }
The text was updated successfully, but these errors were encountered:
778ca59
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: