单词积累
prime number 质数、素数
思路
每行id的行号代表当前id的等级,从1开始,如果是1输出Mystery Award
,如果是素数输出Minion
,其他情况输出Chocolate
,如果给的id
不存在,输出Are you kidding?
,加入给的id已经判断过了,则输出Checked
查询时可以用map,因为数字不大,也可以开个数组,直接下标访问
代码
#include <bits/stdc++.h>
using namespace std;
map<string, string> ranks;
int n, m;
bool isPrime(int ask) {
for (int i = 2; i <= sqrt(ask); i++) {
if (ask % i == 0) return false;
}
return true;
}
int main() {
cin>>n;
for (int i = 1; i <= n; i++) {
string str1;
cin>>str1;
if (i == 1) ranks[str1] = "Mystery Award";
else if (isPrime(i) == true) ranks[str1] = "Minion";
else ranks[str1] = "Chocolate";
}
cin>>m;
for (int i = 0; i < m; i++) {
string str2;
cin>>str2;
if (ranks.find(str2) != ranks.end()) {
cout<<str2<<": "<<ranks[str2]<<endl;
ranks[str2] = "Checked";
} else {
cout<<str2<<": "<<"Are you kidding?"<<endl;
}
}
}