9 degrees OJ 1052 find x, 9 degrees oj1052
Question 1052: Find x
Time Limit: 1 second
Memory limit: 32 MB
Special question: No
Submit: 5182
Solution: 2761
-
Description:
-
Input n numbers, input n numbers are different, input another value x, output the subscript of this value in this array (starting from 0, if not in the array, output-1 ).
-
Input:
-
There are multiple groups of test data. Input n (1 <= n <= 200), then input n numbers, and then input x.
-
Output:
-
Output results for each group of inputs.
-
Sample input:
-
21 30
-
Sample output:
-
-1
#include<stdio.h>int data[201];int main(int argc, char *argv[]){ int n; int i; for(i=0;i<201;++i) data[i]=-2; while(scanf("%d",&n)!=EOF) { int tmp; for(i=0;i<n;++i){ scanf("%d",&tmp); data[tmp]=i; } scanf("%d",&tmp); if(data[tmp]!=-2) printf("%d\n",data[tmp]); else printf("-1\n"); } return 0;} /************************************************************** Problem: 1052 User: kirchhoff Language: C Result: Accepted Time:0 ms Memory:916 kb****************************************************************/