민듀키티

[240518] 코딩테스트 문제풀이 본문

Coding Test/Python

[240518] 코딩테스트 문제풀이

민듀키티 2024. 5. 18. 16:00

1. 랜선 자르기

https://www.acmicpc.net/problem/1654

  • 시간초과
n,m = map(int, input().split())
A = list()

for i in range(n) :
    A.append(int(input()))

number = 0
while True :
    answer = 0
    number += 1

    for i in range(n) :
        answer += (A[i]//number)


    if answer < m :
        break


print(number-1)

 

 


2. 한국이 그리울 땐 서버에 접속하지

https://www.acmicpc.net/problem/9996

n = int(input())
N = list(input().split("*"))
length = len(N[0]) + len(N[1])

for _ in range(n) :
    A = input()

    if len(A) >= length and A.startswith(N[0]) and A.endswith(N[1]) :
        print("DA")
    else :
        print("NE")

 


3. 가희와 키워드

https://www.acmicpc.net/problem/22233

import sys
n,m = map(int, sys.stdin.readline().split(' '))
A = set()

for i in range(n) :
    A.add(sys.stdin.readline().rstrip())

for j in range(m) :
    input_word = list(sys.stdin.readline().rstrip().split(','))
    for word in input_word :
        A.discard(word)

    print(len(A))

 


4.  ROT 13

https://www.acmicpc.net/problem/11655

alph_low = ['a','b','c','d','e','f','g','h','i','j',
        'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
alph_big = ['A','B','C','D','E','F','G','H','I','J',
            'K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']

A = list(input())

for i in A :
        if  i != ' ' and i in alph_big :
                index_number = ( alph_big.index(i) + 13 ) % 26
                print(alph_big[index_number],end = '')
        elif i != ' ' and i in alph_low :
                index_number = (alph_low.index(i) + 13) % 26
                print(alph_low[index_number],end = '')
        else :
                print(i,end = '')

 


5. 수학숙제

n = int(input())
alph = ['a','b','c','d','e','f','g','h','i','j',
        'k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

answer = []
for i in range(n) :
    A = list(input())
    stack = []

    for i in A :
        if i in alph :
            if len(stack) > 0 :
                answer.append(int(''.join(stack)))
                stack = []

        else :
            stack.append(i)

    if len(stack) > 0 :
        answer.append(int(''.join(stack)))


answer.sort()
for number in answer :
    print(number)

 


6. 영단어 암기는 괴로워

https://www.acmicpc.net/problem/20920

import sys
from collections import Counter
import heapq

n,m = map(int, sys.stdin.readline().rstrip().split())
words = list()

# input 값 받기
for i in range(n) :
    input_word = sys.stdin.readline().rstrip()
    if len(input_word) >= m :
        words.append(input_word)

# 자주 나오는 단어 -> 해당 단어의 길이가 길수록 -> 사전 순으로
counter_word = Counter(words)
heap = []
for i in counter_word.items() :
    heapq.heappush(heap, (-i[1], -len(i[0]), i[0]))

for i in range(len(heap)) :
    a,b,c = heapq.heappop(heap)
    print(c)

 


7. 윷놀이

https://www.acmicpc.net/problem/2490

for _ in range(3) :
    A = list(input().split())
    zero_count = A.count("0")
    one_count = A.count("1")

    answer = (zero_count, one_count)

    if answer == (1,3) :
        print("A")
    elif answer == (2,2) :
        print("B")
    elif answer == (3,1) :
        print("C")
    elif answer == (4,0) :
        print("D")
    else :
        print("E")