首页 > 试题广场 >

找x

[编程题]找x
  • 热度指数:21842 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
输入一个数n,然后输入n个数值各不相同,再输入一个值x,输出这个值在这个数组中的下标(从0开始,若不在数组中则输出-1)。

输入描述:
测试数据有多组,输入n(1<=n<=200),接着输入n个数,然后输入x。


输出描述:
对于每组输入,请输出结果。
示例1

输入

2
1 3
0

输出

-1

python两行:

while True:
    try:
        a,b,c=input(),list(map(int,input().split())),int(input())
        print(b.index(c) if c in b else -1)
    except:
        break
发表于 2017-10-16 18:17:39 回复(1)
try:
    while 1:
        n = input()
        L = map(int, raw_input().split())
        try:
        	print L.index(input())
        except:
            print -1
except:
    pass

发表于 2016-12-26 22:19:30 回复(0)