每日打卡,超时,错误一小处,动态数组记得释放

zhaoqianwan / 2023-05-21 / 原文

#include<iostream>
using namespace std;
int sushu(int x)
{
int count = 0;
for (int i = 2; i <= x / 2 + 1; i++)
{
if (x % i == 0)
{
count++;
}
}
if (count >= 1)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int N, K, M;
cin >> N;
string* a = new string[N];
int* c = new int[N];
for (int i = 0; i < N; i++)
{
c[i] = 0;
}
for (int i = 0; i < N; i++)
{
cin >> a[i];
}
cin >> K;
string* b = new string[K];
for (int i = 0; i < K; i++)
{
cin >> b[i];
}
for (int i = 0; i < K; i++)
{
int count = 0;
for (int j = 0; j < N; j++)
{
if (b[i] == a[j])
{
c[j]++;
count++;
M = sushu(j + 1);
if (M == 0 && j != 0&&c[j]<=1)
{
cout << b[i] << ": " << "Minion";
}
else if (j == 0)
{
cout << b[i] << ": " << "Mystery Award";
}
else if (c[j] > 1)
{
cout << b[i] << ": " << "Checked";
}
else
{
cout << b[i] << ": " << "Chocolate";
}
if (i != K - 1)
{
cout << endl;
}
}
}
if (count == 0)
{
cout << b[i] << ": " << "Are you kidding?";
if (i != K - 1)
{
cout << endl;
}
}
}
delete[]a;
delete[]b;
delete[]c;
return 0;
}