DAY 6
0

6/150_UVa100、UVa10222

• 100 -The 3n 1 problem(time out
• 10222 - Decode the Mad man(wrong anser

100 -The 3n 1 problem(time out

``````#宣告
global cach #全域變數
cach={1:1} #紀錄該數字會運算次數，之後可以節省運算

def main():
sinput=input()
while (sinput!=""):
num_1,num_2=map(int,sinput.split())
chobig(num_1,num_2) #進入運算
sinput=input()
``````

``````def chobig(o,t):
biged=max(o,t)
bigst=min(o,t)
big=0

#比較次數最大值
for i in range(bigst,biged+1):
big=max(tre(i),big)
print(o,t,big)
``````

``````def tre(num):
count=cach.get(num)
orin=num

if(count==None):
if (num%2==0):
num=int(num/2)
else:
num=num*3+1
count=tre(num)+1
cach[orin]=count
return count

main()
``````

10222 - Decode the Mad man(wrong anser

``````import string
def inp():
sinp=input().strip()
cha(sinp)

def cha(st):
row1="qwertyuiop[]"
row2="asdfghjkl;'"
row3="zxcvbnm,./"
no=("q","w","a","s","z","x")
for i in range(len(st)):
thst=st[i]
if (st[i]==" "):
print(end=" ")
else:
thst=thst.lower()
if thst not in no:
ifrow(row1,thst)
ifrow(row2,thst)
ifrow(row3,thst)
``````

no列表示不存在範圍

``````def ifrow(row,x):
for i in range(len(row)):
if (x == row[i]):
print(row[(i-2)],end="")

inp()

``````