2021-05-16 20:41

# PAT乙级1059C语言竞赛（20分）运行超时，求大佬解答

``````#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

bool isPrime(int c) {
for (int i = 2; i <= sqrt(c); i++) {
if (c % i == 0) return false;
}
return true;
}

int main() {
int N; cin >> N;
vector<string> vec(N), checked;
for (int i = 0; i < N; i++) cin >> vec[i];
int m; cin >> m;
string c;
int rank;
for (int i = 0; i < m; i++) {
cin >> c;
if (find(checked.begin(), checked.end(), c) != checked.end()) { cout << c << ": Checked" << endl; continue; }
rank = find(vec.begin(), vec.end(), c) - vec.begin();
if (rank == N) cout << c << ": Are you kidding?" << endl;
else if (rank == 0) { cout << c << ": Mystery Award" << endl; checked.push_back(c); }
else if (isPrime(rank+1)) { cout << c << ": Minion" << endl; checked.push_back(c); }
else { cout << c << ": Chocolate" << endl; checked.push_back(c); }
}
return 0;
}``````
• 写回答
• 好问题 提建议
• 追加酬金
• 关注问题
• 收藏
• 邀请回答

#### 4条回答默认 最新

• CSDN专家-三岁丫 2021-05-16 20:57
已采纳

能提供一下题目吗？获取题目链接也行。还有测试点1和测试点2超时的话，有没有输入的样例呢？

评论
解决 无用
打赏 举报