Source https://www.acmicpc.net/problem/15828 15828번: Router 인터넷을 사용하기 위해서는 컴퓨터에 인터넷 회선을 연결하거나 Wi-Fi를 연결해야 한다. 이렇게 연결된 네트워크를 통해 컴퓨터에는 통신이 가능하다. 마음에 드는 노래나 동영상이 있는 곳에 www.acmicpc.net Code import sys from collections import deque input = sys.stdin.readline N = int(input()) # 버퍼의 크기 Router = deque() # 라우터 큐 선언 while True: num = int(input()) if num == 0: Router.popleft() elif num == -1: if Router: pr..
Problem solve
[백준] 1874번 스택 수열 (Python) Soure https://www.acmicpc.net/problem/1874 1874번: 스택 수열 1부터 n까지에 수에 대해 차례로 [push, push, push, push, pop, pop, push, push, pop, push, push, pop, pop, pop, pop, pop] 연산을 수행하면 수열 [4, 3, 6, 8, 7, 5, 2, 1]을 얻을 수 있다. www.acmicpc.net Code import sys input = sys.stdin.readline n = int(input()) stack = [0] print_stack = [] def stack_sequence(): cnt = 1 # cnt가 늘어나며 push되는 값을 관리한다..
[백준] 2108 통계학 (Python) Source https://www.acmicpc.net/problem/2108 2108번: 통계학 첫째 줄에 수의 개수 N(1 ≤ N ≤ 500,000)이 주어진다. 단, N은 홀수이다. 그 다음 N개의 줄에는 정수들이 주어진다. 입력되는 정수의 절댓값은 4,000을 넘지 않는다. www.acmicpc.net Code import collections import sys input = sys.stdin.readline n = int(input()) mid = n//2 + 1 n_sum = 0 n_min, n_max = sys.maxsize, -sys.maxsize l = [] dic = collections.defaultdict(int) for i in range..
[백준] 2295번 세 수의 합 (Python) Source https://www.acmicpc.net/problem/2295 2295번: 세 수의 합 우리가 x번째 수, y번째 수, z번째 수를 더해서 k번째 수를 만들었다라고 하자. 위의 예제에서 2+3+5=10의 경우는 x, y, z, k가 차례로 1, 2, 3, 4가 되며, 최적해의 경우는 2, 3, 4, 5가 된다. k번째 수가 최 www.acmicpc.net Code import sys input = sys.stdin.readline n = int(input()) nums = set(int(input()) for i in range(n)) ## 중복 제거 nums = list(nums) nums.sort() nums_sum = set() for..
[백준] 10989 수 정렬하기3 (Python) Source https://www.acmicpc.net/problem/10989 10989번: 수 정렬하기 3 첫째 줄에 수의 개수 N(1 ≤ N ≤ 10,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 수가 주어진다. 이 수는 10,000보다 작거나 같은 자연수이다. www.acmicpc.net Code import collections import sys input = sys.stdin.readline n = int(input()) dic = collections.defaultdict(int) for i in range(n): temp = int(input()) dic[temp] += 1 list_dic = sorted(dic.items()) ..
[백준] 3283번 두 수의 합 (Python) Source https://www.acmicpc.net/problem/3273 3273번: 두 수의 합 n개의 서로 다른 양의 정수 a1, a2, ..., an으로 이루어진 수열이 있다. ai의 값은 1보다 크거나 같고, 1000000보다 작거나 같은 자연수이다. 자연수 x가 주어졌을 때, ai + aj = x (1 ≤ i int: # brute-force 구현 cnt = 0 for i in range(len(nums)): for j..
[백준] 4358 생태학 (Python) Source https://www.acmicpc.net/problem/4358 4358번: 생태학 프로그램은 여러 줄로 이루어져 있으며, 한 줄에 하나의 나무 종 이름이 주어진다. 어떤 종 이름도 30글자를 넘지 않으며, 입력에는 최대 10,000개의 종이 주어지고 최대 1,000,000그루의 나무가 주어 www.acmicpc.net Code import collections import sys cnt = 0 trees = collections.defaultdict(float) while True: input = sys.stdin.readline().rstrip() ## input으로 문자 받기 if not input: ## EOF 처리 for tree in tr..
[백준] 10820 문자열 분석 (Python) Source https://www.acmicpc.net/problem/10820 10820번: 문자열 분석 문자열 N개가 주어진다. 이때, 문자열에 포함되어 있는 소문자, 대문자, 숫자, 공백의 개수를 구하는 프로그램을 작성하시오. 각 문자열은 알파벳 소문자, 대문자, 숫자, 공백으로만 이루어져 있 www.acmicpc.net Code import re while True: try: words = input() except: break lower_word = re.findall('[a-z]', words) upper_word = re.findall('[A-Z]', words) num = re.findall('[0-9]', words) space = re.f..
[백준] 1175 카드 정렬하기 (Python) Source https://www.acmicpc.net/problem/1715 1715번: 카드 정렬하기 정렬된 두 묶음의 숫자 카드가 있다고 하자. 각 묶음의 카드의 수를 A, B라 하면 보통 두 묶음을 합쳐서 하나로 만드는 데에는 A+B 번의 비교를 해야 한다. 이를테면, 20장의 숫자 카드 묶음과 30장 www.acmicpc.net Code import sys from collections import deque from bisect import bisect_left input = sys.stdin.readline n = int(input()) cards = [int(input()) for i in range(n)] cards.sort() cards ..
[백준] 1259번 팰린드롬수 (Python) Source https://www.acmicpc.net/problem/1259 1259번: 팰린드롬수 입력은 여러 개의 테스트 케이스로 이루어져 있으며, 각 줄마다 1 이상 99999 이하의 정수가 주어진다. 입력의 마지막 줄에는 0이 주어지며, 이 줄은 문제에 포함되지 않는다. www.acmicpc.net Code import sys input = sys.stdin.readline def isPalindrome(s: str) -> bool: return s == s[::-1] while True: s = str(input().rstrip()) if s == '0': break if isPalindrome(s): print('yes') else: print(..