https://www.acmicpc.net/problem/10828
stack = [] for i in xrange(input()): com = raw_input() if com[1]=='u': stack.append(int(com.split()[1])) elif com[0]=='p' and com[1]=='o': print -1 if len(stack)==0 else stack.pop() elif com[1]=='i': print len(stack) elif com[1]=='m': print 1 if len(stack)==0 else 0 elif com[1]=='o': print -1 if len(stack)==0 else stack[-1]
https://www.acmicpc.net/problem/10845
q = [] for i in xrange(input()): c = raw_input() if c[1]=='u': q.append(int(c.split()[1])) elif c[1]=='o': print -1 if len(q)==0 else q.pop(0) elif c[1]=='i': print len(q) elif c[0]=='e': print 1 if len(q)==0 else 0 elif c[0]=='f': print -1 if len(q)==0 else q[0] elif c[0]=='b': print -1 if len(q)==0 else q[-1]
https://www.acmicpc.net/problem/1874
# -*- encoding: cp949 -*- stack = [] n = int(raw_input()) _print = '' index = 1 flag = False for i in xrange(n): p = int(raw_input()) if p > n or (len(stack)>0 and stack[-1] > p): flag = True break while True: if index > p: break stack.append(index) _print += '+\n' index += 1 stack.pop() _print += '-\n' if flag: print 'NO' else: print _print[:-1]
https://www.acmicpc.net/problem/9933
# -*- encoding: cp949 -*- answer = '' name = [raw_input() for i in xrange(int(raw_input()))] flag = False for i in xrange(len(name)): for j in xrange(len(name)): if name[i][::-1]==name[j]: answer += str(len(name[i]))+' '+name[i][len(name[i])/2] print answer flag = True break if flag: break
'algorithm > problem solving' 카테고리의 다른 글
acmicpc.net 1213(팰린드롬), 8892(팰린드롬), 1924 (0) | 2016.08.27 |
---|---|
acmicpc.net 1786(kmp), 1305(kmp), 1157 (0) | 2016.08.25 |
acmicpc.net 9012(스택), 2504(스택) (0) | 2016.08.17 |
acmicpc.net 11723(비트마스크) (0) | 2016.08.15 |
acmicpc.net 1931(그리디), 1744(그리디?), 2846 (0) | 2016.08.14 |