题解 | #找x#
找x
https://www.nowcoder.com/practice/069e2130430c41229ab25e47fa0949a6
#include "cstdio" #include "algorithm" using namespace std; int main() { int n, x; scanf("%d", &n); int arr[n + 1]; for (int i = 0; i < n; ++i) { scanf("%d", &arr[i]); } scanf("%d", &x); int i = 0; for (; i < n; ++i) { if (x == arr[i]) { printf("%d", i); break; } } if (i == n) { printf("%d", -1); } return 0; }