题目链接https://pintia.cn/problem-sets/994805342720868352/problems/994805355358306304
题目大意:按排名给出一串ID,然后在给出一串ID,求其排名对应的奖励。如果一个query合法并且已经输出过,要说checked
思路:正常做,注意排名是从1开始排的即可。
完整代码
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>using namespace std;int ranklist[10001];
bool known[10001];bool isPrime(int num) {
if (num == 1)return false;if (num == 2 || num == 3)return true;for (int i = 2; i <= (int)(sqrt(num)); i++) {
if (num % i == 0)return false;}return true;
}void award(int q) {
printf("%04d: ", q);if (known[q]) {
printf("Checked\n");return;}int r = ranklist[q];if (r == -1)printf("Are you kidding?\n");else if (r == 1) {
printf("Mystery Award\n");known[q] = true;}else if (isPrime(r)){
printf("Minion\n");known[q] = true;}else {
printf("Chocolate\n");known[q] = true;}
}int main() {
fill(ranklist, ranklist+10000, -1);int N, K;scanf("%d", &N);for (int r = 1; r <= N; r++) {
int id;scanf("%d", &id);ranklist[id] = r;}scanf("%d", &K);for (int i = 0; i < K; i++) {
int query;scanf("%d", &query);award(query);}return 0;
}