#include<iostream> using namespace std; //线性查找 const int maxN = 205; int arr[maxN]; int main() { int n; int x; int pos = -1; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); } scanf("%d", &x); pos = -1; //一定记得每个case要重新初始化 for (int i = 0; i < n; i++) { if (x == arr[i]) { pos = i; break; } } printf("%d\n", pos); } }
简单题要更快