Archive/BOJ

Archive/BOJ

백준 11723번: 집합

www.acmicpc.net/problem/11723 11723번: 집합 첫째 줄에 수행해야 하는 연산의 수 M (1 ≤ M ≤ 3,000,000)이 주어진다. 둘째 줄부터 M개의 줄에 수행해야 하는 연산이 한 줄에 하나씩 주어진다. www.acmicpc.net 구현 언어: 파이썬 import sys input = sys.stdin.readline n = int(input()) s = [] for i in range(n): command = list(input().split()) if command[0] == 'add': if command[1] not in s: s.append(command[1]) elif command[0] == 'remove': if command[1] in s: s.remove(..

Archive/BOJ

백준 10816번: 숫자 카드 2

www.acmicpc.net/problem/10816 10816번: 숫자 카드 2 첫째 줄에 상근이가 가지고 있는 숫자 카드의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 둘째 줄에는 숫자 카드에 적혀있는 정수가 주어진다. 숫자 카드에 적혀있는 수는 -10,000,000보다 크거나 같고, 10, www.acmicpc.net 구현 언어: 파이썬 import sys input = sys.stdin.readline n = int(input()) n_list = list(map(int, input().split())) m = int(input()) m_list = list(map(int, input().split())) dic = dict() for i in n_list: try: dic[i] += 1 ..

Archive/BOJ

백준 9012번: 괄호

www.acmicpc.net/problem/9012 9012번: 괄호 괄호 문자열(Parenthesis String, PS)은 두 개의 괄호 기호인 ‘(’ 와 ‘)’ 만으로 구성되어 있는 문자열이다. 그 중에서 괄호의 모양이 바르게 구성된 문자열을 올바른 괄호 문자열(Valid PS, VPS)이라고 www.acmicpc.net 구현 언어: 파이썬 import sys input = sys.stdin.readline n = int(input()) for i in range(n): VPS_input = list(input().strip()) checker = 0 for i in range(len(VPS_input)): if VPS_input[i] == '(': checker += 1 if VPS_input[i..

Archive/BOJ

백준 10866번: 덱

www.acmicpc.net/problem/10866 10866번: 덱 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 구현 언어: 파이썬 import sys input = sys.stdin.readline n = int(input()) deque = [] for i in range(n): command = list(input().split()) if command[0] == 'push_front': deque.insert(0, command[1]) elif command[0] == 'push_back': deq..

Archive/BOJ

백준 10845번: 큐

www.acmicpc.net/problem/10845 10845번: 큐 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 구현 언어: 파이썬 import sys input = sys.stdin.readline n = int(input()) queue = [] for i in range(n): command = list(input().split()) if command[0] == 'push': queue.append(int(command[1])) elif command[0] == 'pop': if queue: pri..

Archive/BOJ

백준 10828번: 스택

www.acmicpc.net/problem/10828 10828번: 스택 첫째 줄에 주어지는 명령의 수 N (1 ≤ N ≤ 10,000)이 주어진다. 둘째 줄부터 N개의 줄에는 명령이 하나씩 주어진다. 주어지는 정수는 1보다 크거나 같고, 100,000보다 작거나 같다. 문제에 나와있지 www.acmicpc.net 구현 언어: 파이썬 import sys input = sys.stdin.readline n = int(input()) stack = [] for i in range(n): command = list(input().split()) if command[0] == 'push': stack.append(int(command[1])) elif command[0] == 'pop': if stack: pr..

Archive/BOJ

백준 11866번: 요세푸스 문제 0

www.acmicpc.net/problem/11866 11866번: 요세푸스 문제 0 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 1,000) www.acmicpc.net 구현 언어: 파이썬 n, k = map(int, input().split()) nums = [i + 1 for i in range(n)] print("") 시도 횟수: 2 구현 포인트: k만큼의 루프를 돌면서 인덱스가 k보다 작은 경우에는 맨 뒤에 append, 맨 앞 값 삭제를 동시에 하고, k번째에는 가장 앞에 있는 수를 프린트 후 팝 (삭제)

Archive/BOJ

백준 10989번: 수 정렬하기 3 (실패)

www.acmicpc.net/problem/10989 10989번: 수 정렬하기 3 첫째 줄에 수의 개수 N(1 ≤ N ≤ 10,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 숫자가 주어진다. 이 수는 10,000보다 작거나 같은 자연수이다. www.acmicpc.net 구현 언어: 파이썬 n = int(input()) data = [] for _ in range(n): x = input() data.append(x) for i in sorted(data): print(i) 시도 횟수: 1 구현 포인트: 메모리 초과라는데 .. 새로운 방법을 생각해야 한다

Archive/BOJ

백준 10814번: 나이순 정렬

www.acmicpc.net/problem/1181 1181번: 단어 정렬 첫째 줄에 단어의 개수 N이 주어진다. (1 ≤ N ≤ 20,000) 둘째 줄부터 N개의 줄에 걸쳐 알파벳 소문자로 이루어진 단어가 한 줄에 하나씩 주어진다. 주어지는 문자열의 길이는 50을 넘지 않는다. www.acmicpc.net 구현 언어: 파이썬 n = int(input()) data = [] tmp = "" for _ in range(n): x = input() data.append(x) for i in sorted(data, key=lambda x: (len(x), x)): if i != tmp: tmp = i print(i) 시도 횟수: 1 구현 포인트: sorted와 람다 식을 연습할 수 있었던 문제

Archive/BOJ

백준 1436번: 영화감독 숌

www.acmicpc.net/problem/1436 1436번: 영화감독 숌 666은 종말을 나타내는 숫자라고 한다. 따라서, 많은 블록버스터 영화에서는 666이 들어간 제목을 많이 사용한다. 영화감독 숌은 세상의 종말 이라는 시리즈 영화의 감독이다. 조지 루카스는 스타 www.acmicpc.net 구현 언어: 파이썬 n = int(input()) sixes = [] for i in range(2666800): if '666' in str(i): sixes.append(i) print(sixes[n-1]) 시도 횟수: 2 구현 포인트:

Danna 다나
'Archive/BOJ' 카테고리의 글 목록 (2 Page)