题解 | 找x
找x
https://www.nowcoder.com/practice/069e2130430c41229ab25e47fa0949a6
#include <bits/stdc++.h> using namespace std; const int MAXN = 200; int arr[MAXN]; int main() { int n; while(cin >> n) { for(int i = 0; i < n;++i) { cin >> arr[i]; } int x; cin >> x; bool found = false; for(int i = 0; i < n; ++i) { if(arr[i] == x) { cout << i << endl; found = true; break; } } if (!found) { cout << -1 << endl; } } return 0; }