[CodeForces 471A] MUH and Sticks

题目链接:http://codeforces.com/problemset/problem/471/A

题目数据规模1 ~ 9,可以用一个数组进行计数,减掉出现四次的数,看看还有几个是非零数,有一个就是大象,有两个就是北极熊;如果没有四个数的,那就是Alien。

AC代码:

#include <cstdio>

using namespace std;

int cnt[10];
int x, id;

int main() {
    id = 0;
    cnt[10] = {0};
    for (int i = 0; i < 6; i++) {
        scanf("%d", &x);
        cnt[x]++;
        if (cnt[x] == 4) {
            id = x;
        }
    }
    if (!id) {
        puts("Alien");
        return 0;
    }
    cnt[id] -= 4;
    int ans = 0;
    for (int i = 0; i < 10; i++) {
        if (cnt[i]) {
            ans++;
        }
    }
    if (ans == 1) {
        puts("Elephant");
    } else {
        puts("Bear");
    }
    return 0;
}
原文地址:https://www.cnblogs.com/youpeng/p/10744838.html