728x90
반응형

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

from math import ceil, floor

for _ in range(int(input())):
    y, m, d = map(int, input().split())
    total = now = 0
    for i in range(1, 1000):
        if i%3 == 0:
            total += 20*10
        else:
            total += (20+19)*5
    total += 1
    
    for i in range(1, y):
        if i%3 == 0:
            now += 20*10
        else:
            now += (20+19)*5
    if y%3 == 0:
        now += (m-1)*20 + d
    else:
        now += ceil((m-1)/2)*20 + floor((m-1)/2)*19 + d
    print(total-now)
728x90
반응형
728x90
반응형

단순 수학 문제이다.

for a in range(int(input())):
    if a != 0:
        print()
    n = int(input())
    s = 0
    for i in range(1, n):
        if n%i == 0:
            s += i
    if s == n:
        print("%d is a perfect number." % (n))
    elif s < n:
        print("%d is a deficient number." % (n))
    else:
        print("%d is an abundant number." % (n))
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
반응형

단순 수학 문제이다. 파이썬은 큰 수들을 신경 쓸 필요가 없어서 참 편하다

for i in range(int(input())):
    a = int(input())
    b = int(input())
    if i != 0:
        print()
    print(a//b)
    print(a%b)
728x90
반응형
728x90
반응형

단순 구현 문제이다.

n = int(input())
cnt = 0
for i in range(6):
    for j in range(i, 6):
        if i+j == n:
            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
반응형

단순 사칙연산 문제이다.

진수 문제 관련해서는 파이썬에 int, oct, hex 등 다양한 내장 함수들이 있어서 쉽게 풀 수 있는 것 같다. 

print(oct(int(input(), 2))[2:])
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
반응형

+ Recent posts