-
Title Description:
-
Enter a number n, then enter n values to be different, enter a value x, and output this value in the array subscript (starting from 0, if not in the array then output-1).
-
Input:
-
Test data has multiple groups, enter N (1<=n<=200), then enter n number, and then enter X.
-
Output:
-
For each set of inputs, output the results.
-
Sample input:
-
21 30
-
Sample output:
-
-1
-
Source:
- 2010 The computer Research of Harbin Institute of Technology The real problem
-
-
Answering:
Problem solving problems? to discuss the subject of discussion please visit: http://t.jobdu.com/thread-7776-1-1.html
#include <iostream>using namespace Std;int main () { int n,i,a[201],m,k; while (Cin>>n) { k=-1; for (i=0;i<n;i++) { cin>>a[i]; } cin>>m; for (i=0;i<n;i++) { if (a[i]==m) { k=i; cout<<k<<endl; break; } } if (i==n) cout<<k<<endl; } return 0;} /************************************************************** problem:1052 user:vhreal language:c++ result:accepted time:0 ms memory:1520 kb******************************************** ********************/
Nine degrees oj-topic 1052: Find X