목록전체 글 (601)
sm 기술 블로그
import sys input = sys.stdin.readline N = int(input()) cnt = 0 stack = [] result = [] for i in range(N): T = int(input()) while cnt < T: cnt += 1 stack.append(cnt) result.append("+") if stack[-1] == T: result.append("-") stack.pop() else: print("NO") stack.append(1) break if not stack: print("\n".join(result)) 문제요약 스택을 이용하여 입력 값이 되도록 해라 설명 while cnt < T: cnt += 1 stack.append(cnt) result.append(..
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); while (true) { String[] S = br.readLine().split(""); Stack stack = new Stack(); if(S[0].equals(".")) { break; } for (int i = 0; i < S.length; i++) { if (S[i].equals("(") || ..
while True: S = input() stack = [] if(S == "."): break for val in S: if val == '[' or val == '(': stack.append(val) elif val == ']': if stack and stack[-1] == '[': stack.pop() else: stack.append(1) break elif val == ')': if stack and stack[-1] == '(': stack.pop() else: stack.append(1) break if not stack: print("yes") else: print("no") 문제요약 문자 형식이 맞는지 확인하고 맞으면 yes 틀리면 no를 출력하라. 설명 stack을 이용하면 쉽게 ..
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T = Integer.parseInt(br.readLine()); for (int i = 0; i < T; i++) { String[] S = br.readLine().split(""); Stack stack = new Stack(); for (int j = 0; j < S.length; j++) { ..