728x90
반응형

단순 구현 문제이다. 

while 1:
    try:
        n, k = map(int, input().split())
        res = 0 
        res += n
        while n//k:
            res += n//k
            n = n//k + n%k
        print(res)
    except:
        break
728x90
반응형
728x90
반응형

단순 사칙연산 문제이다.

for _ in range(int(input())):
    n = int(input())
    t = 0
    while (t+1) + (t+1)**2 <= n:
        t += 1
    print(t)
728x90
반응형
728x90
반응형

단순 구현 문제이다.

while 1:
    p, n = input().split()
    if p == '#':
        break
    n = int(n)
    while 1:
        c, a = input().split()
        if c == 'X':
            break
        a = int(a)
        if a > 68:
            continue
        if c == 'B' and n+a <= 68:
            n += a
        elif c == 'C' and n-a >= 0:
            n -= a
    print(p, n)
728x90
반응형
728x90
반응형

단순 구현 문제이다.

while 1:
    l, w, h, v = map(int ,input().split())
    if l == w == h == v == 0:
        break
    if l == 0:
        l = (v//w//h)
    elif w == 0:
        w = (v//l//h)
    elif h == 0:
        h = (v//l//w)
    elif v == 0:
        v = (l*w*h)
    print(l, w, h, v)
728x90
반응형
728x90
반응형

단순 구현 문제이다.

a = int(input())
b = int(input())
cnt = 2
while a-b >= 0:
    a, b = b, a-b
    cnt += 1
print(cnt)
728x90
반응형
728x90
반응형

단순 구현 문제이다. 

N, M, L = map(int, input().split())
li = [0]*N
cnt = i = 0
while li[i] < M-1:
    li[i] += 1
    cnt += 1
    i = (i+L)%N if li[i]%2 == 1 else (i-L)%N
print(cnt)
728x90
반응형
728x90
반응형

단순 구현 문제이다.

N = int(input())
cnt = 0
t = 1
while N:
    if N < t:
        t = 1
    N -= t
    t += 1
    cnt += 1
print(cnt)
728x90
반응형
728x90
반응형

단순 구현 문제이다. 

N, K = map(int, input().split())
li = list(map(int, input().split(',')))
for _ in range(K):
    t = [li[i+1]-li[i] for i in range(len(li)-1)]
    li = t
print(*li, sep=',')
728x90
반응형
728x90
반응형

그리디 알고리즘 문제이다. 박스 용량의 합에 박스에 들어간 책 크기의 합을 빼주면 된다 -> sum(box) - in_box

N, M = map(int, input().split())
box = list(map(int, input().split()))
book = list(map(int, input().split()))
i = j = t = in_box = 0
while i < N and j < M:
    if box[i] < t+book[j]:
        t = 0
        i += 1
    else:
        in_box += book[j]
        t += book[j]
        j += 1
print(sum(box)-in_box)    
728x90
반응형
728x90
반응형

단순 구현 문제이다.

N, Q = map(int, input().split())
li = [int(input()) for _ in range(N)]
for _ in range(Q):
    t = int(input())
    for i in range(N):
        if t < sum(li[:i+1]):
            print(i+1)
            break
728x90
반응형
728x90
반응형

단순 구현 문제이다. 입력을 한 번에 다 받기 위해 stdin.read() 함수를 사용했다. 

stdin.read()함수를 몰라서 어제 삽질하다가 결국 못 풀었던 문제인데, 방금 알아서 바로 통과했다.

import sys

nums = list(map(int, sys.stdin.read().split()))
for n in nums:
    if n == 0:
        break
    li = []
    for i in range(1, n):
        if n % i == 0:
            if i not in li:
                li.append(i)
            if n//i not in li and n//i != n:
                li.append(n//i)
    if sum(li) == n:
        print(f"{n} PERFECT")
    elif sum(li) < n:
        print(f"{n} DEFICIENT")
    else:
        print(f"{n} ABUNDANT")
728x90
반응형
728x90
반응형

단순 문자열 문제이다. 입력을 한 번에 다 받기 위해 stdin.read() 함수를 사용했다.

import sys

s = sys.stdin.read()
li = [0]*26
for c in s:
    if c.islower():
        li[ord(c)-97] += 1
for i in range(26):
    if li[i] == max(li):
        print(chr(97+i), end='')
728x90
반응형
728x90
반응형

단순하지는 않은 구현(막일) 문제이다.

Month, D, Y, T = input().split()
D = int(D[:-1])
Y = int(Y)
H, M = map(int, T.split(':'))
month_name_li = ["January" , "February", "March", "April", "May", "June", 
            "July", "August", "September", "October", "November", "December"]
month_day_li = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if Y%400 == 0 or (Y%4 == 0 and Y%100 != 0):
    month_day_li[1] += 1
total_time = sum(month_day_li) * 24 * 60

last_month_idx = month_name_li.index(Month)
current_time = (sum(month_day_li[:last_month_idx]) + D-1)*24*60 + H*60 + M
print(current_time/total_time * 100)
728x90
반응형
728x90
반응형

단순 문자열 문제이다. 아스키코드까지 쓸 필요가 없을 것 같아서 그냥 in을 사용해서 풀었다. 

while 1:
    s = input()
    if s == '#':
        break
    cnt = 0
    for c in s:
        if c in 'aeiouAEIOU':
            cnt += 1
    print(cnt)
728x90
반응형
728x90
반응형

단순 구현 문제이다. 딕셔너리와 리스트를 사용해서 두 가지 방식으로 풀어봤다. 

첫 번째 코드가 더 보기 좋은 것 같긴 하다.

s1, s2, s3 = map(int, input().split())
li = [0]*81
for i in range(1, s1+1):
    for j in range(1, s2+1):
        for k in range(1, s3+1):
            li[i+j+k] += 1
print(li.index(max(li)))
s1, s2, s3 = map(int, input().split())
d = {}
for i in range(1, s1+1):
    for j in range(1, s2+1):
        for k in range(1, s3+1):
            d[i+j+k] = d.get(i+j+k, 0) + 1
li = sorted(d.items(), key=lambda x:x[0])
li = sorted(li, key=lambda x:x[1], reverse=True)
print(li[0][0])
728x90
반응형

+ Recent posts