1059 C语言竞赛 (20 分)

#include
#include
#include
#include
#include
#include
#include
using namespace std;

int isPrime(int n){
    int x = floor(sqrt(n) + 0.5);
    for(int i = 2; i <= x; i++){
        if(n%i == 0) return 0;
    }
    return 1;
}

int main(){
    int N;
    scanf("%d", &N);
    int id[10010], used[10010];
    memset(used, -1, sizeof(used));
    memset(id, -1, sizeof(id));
    int x;
    for(int i = 0; i < N; i++){
        scanf("%d", &x);
        used[x] = 1;
        id[x] = i;
    }
    int K;
    scanf("%d", &K);
    for(int i = 0; i < K; i++){
        scanf("%d", &x);
        if(used[x] == 0) {
            printf("%04d: Checked\n", x);
        }else if(used[x] == -1){
            printf("%04d: Are you kidding?\n", x);
        }else if(id[x] == 0){
            printf("%04d: Mystery Award\n", x);
        }else if(isPrime(id[x]+1)){
            printf("%04d: Minion\n", x);
        }else{
            printf("%04d: Chocolate\n", x);
        }
        if(used[x] == 1) used[x] = 0;
    }
}

 

你可能感兴趣的:(PAT)