牛牛的好朋友羊羊在纸上写了n+1个整数,羊羊接着抹除掉了一个整数,给牛牛猜他抹除掉的数字是什么。牛牛知道羊羊写的整数神排序之后是一串连续的正整数,牛牛现在要猜出所有可能是抹除掉的整数。例如:
10 7 12 8 11 那么抹除掉的整数只可能是9
5 6 7 8 那么抹除掉的整数可能是4也可能是9
输入包括2行:
第一行为整数n(1 <= n <= 50),即抹除一个数之后剩下的数字个数
第二行为n个整数num[i] (1 <= num[i] <= 1000000000)
在一行中输出所有可能是抹除掉的数,从小到大输出,用空格分割,行末无空格。如果没有可能的数,则输出mistake
2 3 6
mistake
while True: list_get_str = input('请输入一串整数(以空格分隔)').split(' ') list_get = list(map(int, list_get_str)) list_get.sort() print(list_get) list_length = len(list_get) count = 0 count_list = [] mistake = 0 for i in range(list_length-1): if list_get[i] + 1 == list_get[i+1]: continue elif list_get[i] + 2 == list_get[i + 1]: count += 1 count_list.append(list_get[i]) elif (list_get[i] >= list_get[i+1])&nbs***bsp;(list_get[i] + 2) < list_get[i+1]: print('mistake') mistake = 1 break if mistake == 0: if len(count_list) == 0 : print(list_get[0]-1) print(list_get[-1] + 1) elif len(count_list) == 1: print(count_list[0]) elif len(count_list) >= 2: print('mistake')
#我来用python写一个,见识一下python的强大
def get_the_lose_one(data): data_ordered = sorted(data,lambda x,y:x-y) outcome= [] for index,data in enumerate(data_ordered): if index == len(data_ordered)-2: break if data+1 != data_ordered[index+1]: outcome.append(data+1) if len(outcome) >= 1: print 'mistake' elif not len(outcome): print [data_ordered[0]-1,data_ordered[len(data_ordered)-1]+1] else: print outcome[0]
#coding:utf-8 #author:徐卜灵 n = int(raw_input()) s = [int(x) for x in raw_input().split()] max =max(s) min = min(s) if len(set(s))<max-min: print "mistake" else: if(max - min) == n-1: if min-1>0: print min-1,max+1 else: print max+1 else: for i in range(min+1,max): if i not in s: print i
# -*- coding: utf-8 -*- n = int(raw_input()) num = [int(i) for i in raw_input().split()] # 计算缺少的数字 a = sum(range(min(num), max(num) + 1)) - sum(num) # 如果输入的数字都相同且输入了不止一个数字 if len(set(num)) == 1 and len(num) != 1: print num[0] # 缺少中间数字 elif min(num) < a < max(num): print a # 缺少两端数字 elif a == 0: if min(num) - 1 >= 1: print min(num) - 1, if max(num) + 1 <= 1000000000: print max(num) + 1 else: print 'mistake'
N=int(input('')) str_in=input('') alst=[int(n) for n in str_in.split()] alst.sort() dif=[] for i in range(N-1): dif.append(alst[i+1]-alst[i]) if dif.count(2)==1: idx=dif.index(2) print(alst[idx]+1) elif dif.count(2)==0 and dif.count(1)==N-1: if min(alst)-1<=0: print(max(alst)+1) else: print(str(alst[0]-1)+" "+str(alst[-1]+1)) else: print('mistake')