NC22219. 定位查找
描述
请在给定的数组中查找一个特定的数字,如果该数字出现多次,请输出第一次出现的位置。
输入描述
多组测试,每组第一行输入1个整数n(n<20) 第二行输入n个整数 第三行输入1个整数m
输出描述
查找在第二行的n个整数中第一次出现数字m的下标位置并输出,如果没有找到则输出No,下标从0开始
示例1
输入:
3 4 5 6 5 4 2 2 2 2 2
输出:
1 0
Python(2.7.3) 解法, 执行用时: 19ms, 内存消耗: 2912K, 提交时间: 2020-06-01 11:07:54
try: while True: k=input() n=list(map(int,raw_input().split())) m=int(input()) if m in n: print n.index(m) else: print "No" except: pass
pypy3 解法, 执行用时: 70ms, 内存消耗: 21188K, 提交时间: 2023-07-29 15:32:00
while 1: try: input() n = input().split() i = input() if i in n: print(n.index(i)) else: print("No") except: break
Python3 解法, 执行用时: 60ms, 内存消耗: 7048K, 提交时间: 2021-07-24 23:56:02
import sys for i in sys.stdin: s=list(input().split()) m=input() try: print(s.index(m)) except: print('No')