兩週學會Python 第02天(晚上)
阿新 • • 發佈:2019-01-23
1011 A+B和C (15)
times = int(input())
count = 0
while count < times:
count +=1
lines = input().split(" ")
nums = []
for num in lines:
nums.append(int(num))
if nums[0] + nums[1] >nums[2]:
print("Case #{}: true".format(count))
else:
print("Case #{}: false" .format(count))
1012. 數字分類 (20)
count = [0,0,0,0,0]
result = [0,0,0,0,0]
list = input().split(" ")[1:]
for i in list:
i = int(i)
yu = i%5
if yu==0:
if i%2==0:
result[0] +=i
elif yu==1:
if count[1]%2==0:
result[1] +=i
else:
result[1] -=i
elif yu==2 :
result[2] +=1
elif yu==3:
result[3] += i
else:
if i >result[4]:
result[4] = i
if yu!=0 or (yu==0 and i%2==0):
count[yu] +=1
if count[3]!= 0:
result[3] = round(result[3]*10/count[3])/10
ss = []
for i in range(0,5):
if count[i]!=0:
ss.append(str(result [i]))
else:
ss.append("N")
print(" ".join(ss))
1013 數素數 (20)
import math
prime_number_list = []
string = input().split(" ")
m = int(string[0])
n = int(string[1])
curs = 0
for num in range(2,1000000):
max = math.sqrt(num)
is_prime_number = True
for i in prime_number_list:
if i > max:
break
elif num%i==0:
is_prime_number = False
break
if is_prime_number:
curs +=1
prime_number_list.append(num)
if curs>=n:
break
result = prime_number_list[m-1:]
index = 0
ss = ""
for i in result:
index +=1
if index%10==0:
ss += str(i)
print(ss)
ss = ""
else:
ss =ss + str(i)+" "
if ss!="":
print(ss[0:len(ss)-1])
1014. 福爾摩斯的約會 (20)
import string
dic={'A':'10',
'B':'11',
'C':'12',
'D':'13',
'E':'14',
'F':'15',
'G':'16',
'H':'17',
'I':'18',
'J':'19',
'K':'20',
'L':'21',
'M':'22',
'N':'23'}
week={'A':'MON',
'B':'TUE',
'C':'WED',
'D':'THU',
'E':'FRI',
'F':'SAT',
'G':'SUN'}
s1 = input()
s2 = input()
def get_day(s1, s2 ,fun,f=0,t=0):
for i in range(f,t):
if s1[i]==s2[i]:
a = fun(s1[i])
if a is not None:
return [a,i]
return None
index_to = min(len(s1),len(s2))
day_index_from = get_day(s1,s2,lambda x:week.get(x),t=index_to)
day = day_index_from[0]
index_from = day_index_from[1]+1
hour = int(get_day(s1,s2,lambda x:dic.get(x,x if x in "0123456789" else None),index_from,index_to)[0])
s3 = input()
s4 = input()
index_to = min(len(s3),len(s4))
minute = get_day(s3,s4,lambda x:x if x in string.ascii_letters else None,t=index_to)[1]
print("{0} {1:0>2}:{2:0>2}".format(day,hour,minute))