PAT A1116 come on!Let's C (20)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/maotianyi941005/article/details/60139374
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
map<int,int> ranklist;
const int MAX=10010;
bool hasfound[MAX]={0};
vector<int> query;
vector<int> result;
int isprime(int n){
	int len=sqrt(1.0*n);
	for(int i=2;i<=len;i++){
		if((n%i)==0) return 0;
	}
	return 1;
}
int main(){
	int n,k,i;
	scanf("%d",&n);
	int temp;
	for(i=1;i<=n;i++){
		scanf("%d",&temp);
		ranklist[temp]=i;
	}
	scanf("%d",&k);
	for(i=0;i<k;i++){
		scanf("%d",&temp);
		query.push_back(temp);
	}
	for(i=0;i<k;i++){
		printf("%04d: ",query[i]);
		temp=query[i];
		if(hasfound[temp]==0){
			if(ranklist[temp]>0){
				hasfound[temp]=1;
				if(ranklist[temp]==1) printf("Mystery Award\n");
				else if(isprime(ranklist[temp])==1) printf("Minion\n");
				else printf("Chocolate\n");
			}else printf("Are you kidding?\n");
		}else if(ranklist[temp]>0) printf("Checked\n");
	
	}
	system("pause");
	return 0;
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页