# 找x **题目描述** 输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。 **输入** 测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。 **输出** 对于每组输入,请输出结果。 **样例输入** ```json 4 1 2 3 4 3 ``` **样例输出** ```json 2 ``` 以下程序实现了这一功能,请你填补空白处的内容: ```cpp #include using namespace std; int main() { int n = 0; cin >> n; int *ptr = new (nothrow) int[n]; for (auto i = 0; i < n; i++) { cin >> ptr[i]; } int x = 0; cin >> x; auto j = 0; auto status = 0; for (; j < n; ++j) { ______________ } if (status == 0) { j = -1; } cout << j << endl; delete[] ptr; cin.get(); cin.get(); return 0; } ``` ## template ```cpp #include using namespace std; int main() { int n = 0; cin >> n; int *ptr = new (nothrow) int[n]; for (auto i = 0; i < n; i++) { cin >> ptr[i]; } int x = 0; cin >> x; auto j = 0; auto status = 0; for (; j < n; ++j) { if (ptr[j] == x) { status = 1; break; } } if (status == 0) { j = -1; } cout << j << endl; delete[] ptr; cin.get(); cin.get(); return 0; } ``` ## 答案 ```cpp if (ptr[j] == x) { status = 1; break; } ``` ## 选项 ### A ```cpp if (ptr[j] == x) { status = 1; continue; } ``` ### B ```cpp if (ptr[j] >= x) { status = 1; continue; } ``` ### C ```cpp if (ptr[j] <= x) { status = 1; continue; } ```