/* 1934: find x Topic description Input a number n, then input n different values, and then input a value x, output the subscript of this value in this array (starting from 0, if it is not in the array, output -1). enter There are multiple sets of test data, enter n (1<=n<=200), then enter n numbers, and then enter x. output For each set of inputs, output the result. sample input 4 1 2 3 4 3 Sample output 2 */ #include<cstdio> const int maxn = 210; int a[maxn]; int main(){ int n,x; while(scanf("%d",&n)!=EOF){ for(int i=0;i<n;i++){ scanf("%d",&a[i]); } scanf("%d",&x); int k; for(k=0;k<n;k++){ if(a[k]==x){ printf("%d\n",k); break; } } if(k==n){ printf("-1\n"); } } return 0; }
[Codeup 1934] Find x - find element
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325693322&siteId=291194637
Recommended
Ranking