백준문제풀이/기본수학1

2839번 -- 설탕배탈(수정필요)

포비용 2022. 12. 31.
import sys
import math

sys.stdin = open("input.txt","rt")

x = int(input())

cnt = 0

if (x % 3 != 0) and (x % 5 != 0):
    print(-1)


if ((x % 5) % 3 == 0):

    cnt = x // 5
    x = x % 5

    if x < 3:
        cnt = x
        print(cnt)

    else:
        x = x // 3
        cnt += x
        print(cnt)


elif (x % 3) == 0:

    x = x//3
    cnt = x
    print(cnt)
# 1차 수정 코드 (여전히 답 안맞음)

import sys

sys.stdin = open("input.txt","rt")

x = int(input())

cnt = 0

while True:

    if (x == 1) or (x == 2):
        print(-1)
        break

    elif (x == 4):
        print(-1)
        break

    elif x == 3:
        cnt = 1
        print(cnt)
        break

    elif x >= 5:
        x -= 5
        cnt += 1
        if x == 0:
            print(cnt)
            break

        elif x == 1:
            x += 5
            cnt -= 1
            cnt += x // 3
            print(cnt)
            break

        elif x == 4:
            x += 5
            cnt -= 1
            cnt += x // 3
            print(cnt)
            break

        elif x == 3:
            cnt += x // 3
            print(cnt)
            break
# 정답

import sys

sys.stdin = open("input.txt","rt")

x = int(input())

cnt = 0

if x % 5 == 0:
    cnt = x // 5
    print(cnt)

else:
    while x >= 0:
        x -= 3
        cnt += 1

        if x % 5 == 0:
            cnt += x // 5
            print(cnt)
            break

        elif (x == 1):
            print(-1)
            break

        elif x == 0:
            print(cnt)
            break

'백준문제풀이 > 기본수학1' 카테고리의 다른 글

2775  (0) 2022.12.30
10250  (0) 2022.12.28
2869 달팽이는 올라가고 싶다  (0) 2022.12.27
1193 -- 다시풀이  (0) 2022.12.26
2292  (0) 2022.12.26

댓글