题解 | #找x#
找x
https://www.nowcoder.com/practice/069e2130430c41229ab25e47fa0949a6
#include <iostream> #include <vector> using namespace std; int main() { int n, x; while (cin >> n) { // 注意 while 处理多个 case // cout << a + b << endl; vector<int> q; for (int i = 0; i < n; i++) { cin >> x; q.push_back(x); //形成数组 } cin >> x; for (int i = 0; i < n; i++) { if (q[i] == x) { cout << i << endl; //搜索数组 break; } if (i == n - 1 && q[i] != x) { cout << -1 << endl; //搜索失败 } } } } // 64 位输出请用 printf("%lld")