Newcoder 132 A.有趣的题(水~)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/V5ZSQ/article/details/82917416

Description

6 6 个火柴棍,问能不能拼成“熊”或者“象”

“熊”: 4 4 根棍子长度一样,另外 2 2 根棍子长度不一样

“象”: 4 4 根棍子长度一样,另外 2 2 根棍子长度一样。

如果可以拼出熊,输出 B e a r “Bear”

如果可以拼出象,输出 E l e p h a n t “Elephant”

如果都不可以拼出,输出 H e r n i a “Hernia”

Input

一行六个数表示每个火柴棍的长度,火柴棍长度在 [ 1 , 9 ] [1,9]

Output

输出一行一个字符串表示答案

Sample Input

4 2 5 4 4 4

Sample Output

Bear

Solution

水题

Code

#include<cstdio>
#include<algorithm>
using namespace std;
int a[6];
int main()
{
	for(int i=0;i<6;i++)scanf("%d",&a[i]);
	sort(a,a+6);
	int num=0,x=-1,y=-1;
	for(int i=0;i<6;i++)
		if(a[i]==a[2])num++;
		else if(x==-1)x=a[i];
		else y=a[i];
	if(x==-1)x=a[2];
	if(y==-1)y=a[2];
	if(num<4)printf("Hernia\n");
	else if(x!=y)printf("Bear\n");
	else printf("Elephant\n");
	return 0;
}

猜你喜欢

转载自blog.csdn.net/V5ZSQ/article/details/82917416
132