1059 C language title race 20 points this attention judgment skills primes, in addition to 2, the other is not even prime number.

#include <iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int a[10000] = { 0 }, ran[10000], c[10000] = {0};//a代表是否存在,ran代表序号,c代表是否查找过
bool judge(int a) {
	for (int i = 3; i <= sqrt(a); i += 2) {
		if (a%i == 0)
			return false;
	}
	return true;
}
int main() {
	int n, k;
	cin >> n;
	for (int i = 1; i <=n; i++) {
		int id;
		cin >> id;
		a[id] = 1;
		ran[id] = i;
	}
	cin >> k;
	for (int i = 0; i < k; i++) {
		int t;
		cin >> t;
		if (a[t] == 1) {
			if (c[t] == 1) {
				printf("%04d", t);
				cout << ": Checked" << endl;
			}
			else if (ran[t] == 1) {
				printf("%04d", t);
				cout  << ": Mystery Award" << endl;
			}
			else if (ran[t] == 2) {
				printf("%04d", t);
				cout << ": Minion" << endl;
			}

			else if (ran[t] % 2 == 0) {
				printf("%04d", t);
				cout << ": Chocolate" << endl;
			}
			else if (judge(ran[t]) ) {
				printf("%04d", t);
				cout  << ": Minion" << endl;
			}
			else {
				printf("%04d", t);
				cout << ": Chocolate" << endl;
			}
			
			c[t] = 1;
		}
		else {
			printf("%04d", t);
			cout << ": Are you kidding?" << endl;
		}
	}

}

Note that the output format statement, colon spaces and no less.

Published 17 original articles · won praise 0 · Views 188

Guess you like

Origin blog.csdn.net/w17390956947/article/details/104929049