def helper(arr,item):
if item<1:
return False
if len(arr)==1:
return arr[0]==item
for i in range(len(arr)):
L=arr[:i]+arr[i+1:]
v=arr[i]
if helper(L,item-v)or helper(L,item+v)or helper(L,item*v)or helper(L,item/v):
return True
return False
while True:
try:
arr=list(map(int,input().split(' ')))
if helper(arr,24):
print('true')
else:
print('false')
except:
break
###This is a copy of Orli有异议 ####
import sys
def checkTwoKeys(twoKeys,a,result):
count = 0
index = 0
for y in twoKeys:
if a[0]==y.split()[0][:len(a[0])] and a[1]==y.split()[1][:len(a[1])]:
count += 1
index = twoKeys.index(y)
if count > 1 or count == 0:
print("unkown command")
elif count == 1:
print(result[index])
oneKey = 'reset'
twoKeys = ['reset board','reboot backplane','backplane abort','board add','board delete']
result = ['board fault','impossible','install first','where to add','no board at all']
for i in sys.stdin:
a = i.strip().split()
l = len(a)
if l <= 0 or l>=3:
print("unkown command")
elif l == 1:
if a[0] == oneKey[:len(a[0])]:
print("reset what")
else:
print("unkown command")
elif l == 2:
checkTwoKeys(twoKeys,a,result)
while True:
try:
a=input()
b=input()
if len(a)>len(b):
a,b=b,a
length=0
for i in range(len(a)):
for j in range(i+1,len(a)):
sub=a[i:j]
if sub in b and j-i>length:
res=sub
length=j-i
print(res)
except:
break
while True:
try:
n = int(raw_input())
a = range(n + 1)
order = raw_input()
head, tail, i = 1, 4, 1
if n <= 4:
for s in order:
if s == 'U':
if i == 1:
i = n
else:
i -= 1
else:
if i == n:
i = 1
else:
i += 1
head, tail = 1, n
else:
for s in order:
if s == 'U':
if i == 1:
i = n
head, tail = n - 3, n
else:
i -= 1
if i < head:
head, tail = i, i + 3
else:
if i == n:
i = 1
head, tail = 1, 4
else:
i += 1
if i > tail:
head, tail = i - 3, i
ans = range(head, tail + 1)
print(' '.join([str(j) for j in ans]))
print( i)
except:
breakwhile True:
try:
n = int(raw_input())
a = range(n + 1)
order = raw_input()
head, tail, i = 1, 4, 1
if n <= 4:
for s in order:
if s == 'U':
if i == 1:
i = n
else:
i -= 1
else:
if i == n:
i = 1
else:
i += 1
head, tail = 1, n
else:
for s in order:
if s == 'U':
if i == 1:
i = n
head, tail = n - 3, n
else:
i -= 1
if i < head:
head, tail = i, i + 3
else:
if i == n:
i = 1
head, tail = 1, 4
else:
i += 1
if i > tail:
head, tail = i - 3, i
ans = range(head, tail + 1)
print(' '.join([str(j) for j in ans]))
print( i)
except:
break
while True:
try:
a, b = input(), int(input())
maxStr, maxCnt = a[:b], a[:b].count("C") + a[:b].count("G")
for i in range(0, len(a) - b):
if a[i:i + b].count("C") + a[i:i + b].count("G") > maxCnt:
maxCnt = a[i:i + b].count("C") + a[i:i + b].count("G")
maxStr = a[i:i + b]
print(maxStr)
except:
break
while True:
try:
print(bin(int(input())).count("1"))
except:
break
''''''其实这题考的是数学啊,首先当有0个苹果或者是1个盘子的时候,只有一种分法,而其他情况
可以分为两种情况讨论:
1、m<n,则至少有n-m个盘子是空的,此时就相当于将m个苹果分到m个盘子中,此时(m,n)=(m,m)
2、m > n,分法是两种情况分法的和,有一个空盘子和没有空盘子,即(m,n) = (m,n-1)+(m-n,n)
''''''
def putApple(m,n):
if m == 0 or n == 1:
return 1
if n > m:
return putApple(m,m)
else:
return putApple(m,n-1) + putApple(m-n,n)
while True:
try:
n, m = map(int,input().split())
print(putApple(n, m))
except:
break
def isapse(n):
for i in range(2,n//2+1):
if n%i==0:
return False
return True
while True:
try:
num=int(input())//2
start=1
if num%2==1:
start=0
for i in range(start,num,2):
a,b=num-i,num+i
if isapse(a) and isapse(b):
print(a)
print(b)
break
except:
break
while True:
try:
from collections import Counter
a=input()
c=list(map(lambda c:c[0],list(filter(lambda c:c[1]==1,Counter(a).most_common()))))
if not c:
print(-1)
for i in a:
if i in c:
print(i)
break
except:
break
while True:
try:
num=int(input().split()[1])
ls=map(int,input().split())
print(" ".join(map(str,sorted(ls)[:num])))
except:
break
while True:
try:
print(int(input())+int(input()))
except:
break
while True:
try:
a=int(input())
print(len(list(filter(lambda x: x < a, [6, 28, 496, 8128]))))
except:
break
while True:
try:
num=int(input())
res=0
for i in range(1,num+1):
if i%7==0:
res+=1
elif '7'in str(i):
res+=1
else:
continue
print(res)
except:
break
while True:
try:
a=int(input())
b=int(input())
ls=[]
for i in range(a):
table=input().split(' ')
name,value=table[0],int(table[1])
ls.append((name,value))
if b==0:
newtable=sorted(ls,key=lambda x:x[1],reverse=True)
else:
newtable=sorted(ls,key=lambda x:x[1])
for i in newtable:
print(i[0]+' '+str(i[1]))
except:
break
import re
while True:
try:
pattern, s = input(), input()
pattern = pattern.replace('.', '\\.').replace('?', '.').replace('*', '[0-9A-z]*')
a = re.findall(pattern, s)
print(str(bool(len(a) == 1 and a[0] == s)).lower())
except:
break
study Python 24day
猜你喜欢
转载自blog.csdn.net/u011624267/article/details/103937381
今日推荐
周排行