Description
输入一个从小到大排列的有序数列(长度小于100),在此数列中查找某一个数x,若找到,输出相应下标,否则,输出”Not Found".
Input
先输入要查找的数x和n, 再输入n个有序数。
Output
输出x所在位置下标或"Not Found"
Sample Input
2 8 -2 2 3 8 9 20 25 67 5 7 -2 2 3 8 9 20 25
Sample Output
1 Not Found
代码实现
#include<iostream>
using namespace std
;
int main()
{
int x
,n
,i
,a
[200];
while(cin
>>x
)
{
cin
>>n
;
for(i
=1;i
<=n
;i
++)
cin
>>a
[i
];
for(i
=1;i
<=n
;i
++)
if(x
==a
[i
])
{
cout
<<i
-1<<endl
;
break;
}
if(i
==n
+1)
cout
<<"Not Found"<<endl
;
}
return 0;
}