solution.md 885 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
# 找x

题目描述
输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。
输入
测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。
输出
对于每组输入,请输出结果。
样例输入
4
1 2 3 4
3
样例输出
2


## template

```cpp
#include <iostream>
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

```

## 选项

### A

```cpp

```

### B

```cpp

```

### C

```cpp

```