赞
踩
#include <iostream> #include <map> #include <math.h> using namespace std; bool isPrime(int n){ for(int i=2; i<=sqrt(n); i++){ if(n%i==0){ return false; } } return true; } int main() { int n; scanf("%d", &n); map<int, int> m; for(int i=1; i<=n; i++){ int t; cin>>t; m[t] = i; } int q; scanf("%d", &q); for(int i=1; i<=q; i++){ int t; scanf("%d", &t); if(m[t]>0){ if(m[t]==1){ printf("%04d: Mystery Award\n", t); } else if(isPrime(m[t])){ printf("%04d: Minion\n", t); } else{ printf("%04d: Chocolate\n", t); } m[t] = m[t] * -1; } else if(!m[t]){ printf("%04d: Are you kidding?\n", t); } else{ printf("%04d: Checked\n", t); } } return 0; }
1、素数的判定。从1-sqrt(n),看有没有能整除的,如有,则不是素数。
2、输入数据用map存储,key是编号,value是排名。value默认为0,为0即为未出现。
3、check后value值变为负数,因此value为负数输出checked。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。