题目
思路
思路是用一个结构体散列来记录排名,用一个整型数组散列来记录数据的录入\输出
关于测试点2:是由于素数判别的错误,会误判9为素数。检查素数判别函数即可。
AC代码
#include<bits/stdc++.h>
using namespace std;
struct stu{
int price;
};
bool isprime(int n){
if(n<=1) return false;
for(int i=2;i*i<=n;i++){
if(n%i==0) return false;
}
return true;
}
int main(){
int n; cin>>n;
stu s[10010];
int c[10010]={0}; //用来记录数据情况,1为录入过成绩,2为发放过奖励,0为未录入
string str;
int temp;
for(int i=0;i<n;i++){
cin>>str;
temp=stoi(str);
s[temp].price=i+1;
c[temp]=1;
}
int m; cin>>m;
for(int i=0;i<m;i++){
cin>>str;
temp=stoi(str);
if(c[temp]==0) cout<<temp<<": Are you kidding?"<<endl;
else if(c[temp]==1 && s[temp].price == 1) {
cout<<str<<": Mystery Award"<<endl;
c[temp]=2;
}
else if(c[temp]==1 && isprime(s[temp].price) == 1) {
cout<<str<<": Minion"<<endl;
c[temp]=2;
}
else if(c[temp]==1 && s[temp].price > 1 && isprime(s[temp].price) == 0) {
cout<<str<<": Chocolate"<<endl;
c[temp]=2;
}
else if(c[temp]==2) cout<<str<<": Checked"<<endl;
}
}