是做题做太多了吗,老是有低级小错误。
最后找到数之后,没有break,导致如果有多个相同的数字,会输出多个“YES”。
代码如下:
#include<iostream>
#include<math.h>
#include<string>
#include <iomanip>
#include<stdio.h>
using namespace std;
struct student {
string num;
string name;
string sex;
int age;
};
int main()
{
int n;
while (cin >> n) {
int *a = new int[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int m;
cin >> m;
int *b = new int[m];
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < m; i++) {
int flag = 0;
for (int j = 0; j < n; j++) {
if (a[j] == b[i]) {
cout << "YES" << endl; flag = 1; break;
}
}
if (flag == 0)cout << "NO" << endl;
}
}
system("pause");
return 0;
}