YES! YOU CAN!
Time Limit: 1 Sec Memory Limit: 128 MBDescription
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks.
They can make an animal from sticks in the following way:
Four sticks represent the animal's legs, these sticks should have the same length.
Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations
between the leg sticks and the head and body sticks.
Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it.
Input
There are multiple test cases.
In each test case, there's a single line containing six space-separated integers li (1≤li≤9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks.
Output
If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes).
Sample Input
4 2 5 4 4 4
Sample Output
Bear
分析:这是第一次在OJ上做ACM的题目,感觉ACM的题目都很多隐含的细节,并且题目中只提供了一个案例,其他条件需要自己的深度挖掘。 首先存储六个数,然后用数组统计每个数的出现的次数,然后对此数进行分析。如果没有一个数超过四次,直接输出Alien;有超过四次的数,减去四次,分析剩余的2个的情况。如果两个相同,即为Elephant,否则为Bear。
#include<stdio.h> int main() { int num[6]; int flag; while(scanf("%d %d %d %d %d %d",&num[0],&num[1],&num[2],&num[3],&num[4],&num[5])!=EOF) { int count[10]= {0,0,0,0,0,0,0,0,0,0}; int i,j,k; flag = 0; for(k=0; k<6; k++) count[num[k]]++; for(i=1; i<10; i++) { if(count[i]>=4) { count[i] -= 4; for(j=1; j<10; j++) { if(count[j]==2) { printf("Elephant "); flag = 1; break; } } for(j=0; j<10; j++) { if(count[j]==1) { printf("Bear "); flag = 1; break; } } } } if(!flag) printf("Alien "); } return 0; }
这是第一次做ACM的题目,如有Bug请指正。