-- 예전 기록/BOJ

[ BOJ ] 19602 : Dog Treats ( BRONZE 4 ) / C, Python

rejo 2023. 10. 3. 10:50

문제

Barley the dog loves treats. At the end of the day he is either happy or sad depending on the number and size of treats he receives throughout the day. The treats come in three sizes: small, medium, and large. His happiness score can be measured using the following formula:

1 × S + 2 × M + 3 × L

where S is the number of small treats, M is the number of medium treats and L is the number of large treats.

If Barley’s happiness score is 10 or greater then he is happy. Otherwise, he is sad. Determine whether Barley is happy or sad at the end of the day.

입력

There are three lines of input. Each line contains a non-negative integer less than 10. The first line contains the number of small treats, S, the second line contains the number of medium treats, M, and the third line contains the number of large treats, L, that Barley receives in a day.

출력

If Barley’s happiness score is 10 or greater, output happy. Otherwise, output sad.

풀이 과정

1 x S + 2 x M + 3 x L 이 10보다 크거나 같으면 happy, 그렇지 않으면 sad를 출력한다.

C

#include <stdio.h>

int main(void) {
    int s, m, l;
    scanf("%d", &s);
    scanf("%d", &m);
    scanf("%d", &l);

    if (s+2*m+3*l >= 10) printf("happy");
    else printf("sad");
    return 0;
}

Python

s = int(input())
m = int(input())
l = int(input())

if s+2*m+3*l >= 10: print('happy')
else: print('sad')