描述
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”。
}