童程oj(6450 Dog Treats)

描述

Barley the dog loves treats. At the end of the day he is either happy or sad depending on thenumber 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.
Barley the dog 喜欢美食。一天结束时,他要么高兴,要么悲伤,这取决于他一天中收到的食物的数量和大小。这些零食有三种尺寸:小、中、大。他的幸福感得分可以用以下公式来衡量:
1×S+2×M+3×L
其中 S 是小零食的数量,M 是中等零食的数量并且 L 是大零食的数量。
如果Barley 的幸福感得分是 10 分或更高,那么他就是幸福的。否则,他会很难过。确定 Barley 在一天结束时是高兴还是悲伤。

输入描述

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.

有三行输入。每行包含一个小于 10 的非负整数。第一行包含小零食的数量 S,第二行包含中等零食的数量 M,第三行包含大麦一天收到的大零食的数量 L。

输出描述

If Barley’s happiness score is 10 or greater, output happy. Otherwise, output sad.
如果 Barley 的快乐分数为 10 或更高,则输出 happy。否则,输出 sad

样例输入 1 

3
1
0

样例输出 1 

sad

样例输入 2 

3
2
1

样例输出 2 

happy

代码实现:

#include<iostream>
using namespace std;
int main(){
    int S,M,L;//建立变量;
    cin>>S>>M>>L;
    if(S+M*2+L*3>=10)cout<<"happy";//这里根据公式“S*1+M*2+L*3”,算出值;
    else cout<<"sad";//如果大于10“happy”,小于10“sad”。
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值