题解 | #找x#
找x
https://www.nowcoder.com/practice/069e2130430c41229ab25e47fa0949a6
#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n; int target; vector<int> vec; while (cin >> n) { // 注意 while 处理多个 case vec.clear(); int num; for (int i = 1; i <= n; i++) { cin >> num; vec.emplace_back(num); } cin >> target; //vector<int>::iterator vector<int>::iterator it = find(vec.begin(), vec.end(), target); if (it == vec.end()) { cout << -1 << endl; } else { cout << distance(vec.begin(), it) << endl; } } } // 64 位输出请用 printf("%lld")