题解 | #找x#
找x
https://www.nowcoder.com/practice/069e2130430c41229ab25e47fa0949a6
#include <iostream> using namespace std; int main() { int n; while (cin >> n) { int a[n]; for(int i=0;i<n;i++) { cin>>a[i]; } int x;cin>>x; int i; for( i=0;i<n;i++) { if(x==a[i]){cout<<i<<endl;break;} } if(i==n&&(x!=a[n-1]))cout<<"-1"<<endl; } }