Description
给 6 6 6个火柴棍,问能不能拼成“熊”或者“象”
“熊”: 4 4 4根棍子长度一样,另外 2 2 2根棍子长度不一样
“象”: 4 4 4根棍子长度一样,另外 2 2 2根棍子长度一样。
如果可以拼出熊,输出 “ B e a r ” “Bear” “Bear”
如果可以拼出象,输出 “ E l e p h a n t ” “Elephant” “Elephant”
如果都不可以拼出,输出 “ H e r n i a ” “Hernia” “Hernia”
Input
一行六个数表示每个火柴棍的长度,火柴棍长度在 [ 1 , 9 ] [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;
}