티스토리 뷰

문제 출처 - https://www.acmicpc.net/problem/1874


깃헙 주소 - https://github.com/Younkyu/baekjoon_1874


package com.company;

import java.util.*;

public class Main {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);
//총 몇개의 숫자를 입력 받을 것인지
int count = 0;
int input = 0;
count = sc.nextInt();

if (count > 0) {

Stack<Integer> stack = new Stack<>();
Queue<Integer> su = new LinkedList<>();
Queue<Character> pushpop = new LinkedList<>();

for(int i = 0 ; i < count ; i++) {
su.offer(sc.nextInt());
}

int nowpush = 1;

while (!su.isEmpty()) {
int now = su.poll();

while (stack.isEmpty() || (!stack.isEmpty() && stack.peek() < now)) {
stack.push(nowpush);
pushpop.offer('+');
nowpush = nowpush +1;
}

if (!stack.isEmpty() && stack.peek() == now) {
stack.pop();
pushpop.offer('-');
}else {
System.out.println("NO");
return;
}
}

while (!pushpop.isEmpty()){
System.out.println(pushpop.poll());
}

}else {
System.out.println("NO");
}
}
}


'알고리즘 문제 풀이 ' 카테고리의 다른 글

소들의 줄세우기  (0) 2018.09.18
달팽이 그리기  (0) 2018.09.17
자연수의 합 / Division  (0) 2018.09.17
단지번호 붙이기  (0) 2018.09.17
weird  (0) 2018.07.01
XHAENEUNG - 똥 같은 코드  (0) 2018.01.29
DRAWRECT - 좌표 계산 문제  (0) 2018.01.27
Endians - n진법 표기 관련 문제  (0) 2018.01.25
댓글