fork download
  1. public class Num1874{
  2. public static void main(String[] args) throws Exception {
  3. // Scanner 객체보다 빠르게 하기 위해 사용. 한 줄을 통째로 입력받는다.
  4. StringBuilder sb = new StringBuilder(); // String 연산 시간을 줄이기 위해 사용
  5.  
  6. int n = Integer.parseInt(br.readLine()); // 입력할 숫자 갯수
  7.  
  8. int temp; // 입력한 값
  9. int max = 0; // stack안에서 제일 큰 값
  10. int top = 0; // stack에서 최상단에 있는 값
  11. int[] stack = new int[n];
  12.  
  13. while(n-- > 0){ // 입력받은 값의 수가 0보다 클 때 까지
  14. temp = Integer.parseInt(br.readLine());
  15. if(temp > max){
  16. // 스택에 값이 없을 경우
  17. for(int i=max+1; i<=temp; i++){
  18. stack[top++] = i;
  19. sb.append("+\n"); // push
  20. }
  21. max = temp;
  22. }else if(stack[top-1] != temp) { // 종료조건을 확인하기 위해
  23. System.out.println("NO");
  24. return; // 아예 메소드를 종료시켜야 하기때문에 break을 쓰지 않는다.
  25. }
  26. // 무조건 한번은 pop을 하기 때문에
  27. top--;
  28. sb.append("-\n"); // pop
  29. }
  30. System.out.println(sb);
  31. }
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class Num1874 is public, should be declared in a file named Num1874.java
public class Num1874{
       ^
Main.java:4: error: cannot find symbol
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		^
  symbol:   class BufferedReader
  location: class Num1874
Main.java:4: error: cannot find symbol
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		                        ^
  symbol:   class BufferedReader
  location: class Num1874
Main.java:4: error: cannot find symbol
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		                                           ^
  symbol:   class InputStreamReader
  location: class Num1874
4 errors
stdout
Standard output is empty