代码
#include<iostream>
using namespace std;
int main()
{
int n, k[1000],i;
cin >> n;
for (i = 0; i < n; i++)
{
cin >> k[i];
}
int a;
cin >> a ;
int found = false;// 创建一个布尔变量found,用于标记是否找到整数a
for (int j=0; j < n; j++)
{
if (k[j] == a)
{
cout << j + 1 << endl; // 输出元素a在数组中的位置(位置从1开始计数)
found = true; // 设置found为true,表示找到了元素a
break; // 退出循环,因为我们已经找到了元素a
}
}
if (!found) { // 如果found仍然是false(即没有找到元素a)
cout << "-1" << endl; // 输出-1,表示元素a不在数组中
}
return 0;
}