并找到后输出YES,否则输出NO
时间: 2024-03-11 16:50:25 浏览: 15
好的,那么我们在代码中加入查找和输出结果的逻辑:
```c++
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main() {
int n;
cin >> n;
cin.ignore(); // 忽略换行符
for (int i = 0; i < n; i++) {
string line1, line2;
getline(cin, line1);
getline(cin, line2);
stringstream ss(line1);
int l, temp;
ss >> l;
int* arr = new int[l];
for (int j = 0; j < l; j++) {
ss >> temp;
arr[j] = temp;
}
stringstream ss2(line2);
int target;
ss2 >> target;
// 在arr中查找target
bool found = false;
for (int j = 0; j < l; j++) {
if (arr[j] == target) {
found = true;
break;
}
}
// 输出结果
if (found) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
delete[] arr;
}
return 0;
}
```
在代码中,我们使用一个布尔变量 `found` 记录是否在数组中找到了要查找的值。在循环结束后,根据 `found` 的值输出结果。