a291. nAnB problem - 高中生程式解題系統 (zerojudge.tw)
我的第二次解題,只為了通過解題,但卻無法通過解答:
import sys
for line in sys.stdin:
if line != "\n":
rightlist = [int(temp) for temp in line.split()]
n = int(input())
for i in range(n):
templist = []
for temp in rightlist:
templist.append(temp)
trylist = [int(trytemp) for trytemp in input().split()]
p = 0
q = 0
plist = []
minuslist = []
for j in range(len(trylist)):
if templist[j] == trylist[j]:
p = p + 1
plist.append(j)
minuslist.append(templist[j])
#print(plist)
for k in minuslist:
templist.remove(k)
trylist.remove(k)
#print(templist,trylist)
for l in range(len(templist)):
for m in range(len(trylist)):
if templist[l] == trylist[m]:
q = q + 1
print(str(p)+'A'+str(q)+'B')
else:
break
送出解答:
我的第一次解題,只為了通過測試,但卻無法通過解答:
import sys
rightlist = [int(temp) for temp in input().split()]
n = int(input())
for i in range(n):
templist = []
for temp in rightlist:
templist.append(temp)
trylist = [int(trytemp) for trytemp in input().split()]
p = 0
q = 0
plist = []
minuslist = []
for j in range(len(trylist)):
if templist[j] == trylist[j]:
p = p + 1
plist.append(j)
minuslist.append(templist[j])
#print(plist)
for k in minuslist:
templist.remove(k)
trylist.remove(k)
#print(templist,trylist)
for l in range(len(templist)):
for m in range(len(trylist)):
if templist[l] == trylist[m]:
q = q + 1
print(str(p)+'A'+str(q)+'B')
m = input()
rightlist = [int(temp) for temp in input().split()]
n = int(input())
for i in range(n):
templist = []
for temp in rightlist:
templist.append(temp)
trylist = [int(trytemp) for trytemp in input().split()]
p = 0
q = 0
plist = []
minuslist = []
for j in range(len(trylist)):
if templist[j] == trylist[j]:
p = p + 1
plist.append(j)
minuslist.append(templist[j])
#print(plist)
for k in minuslist:
templist.remove(k)
trylist.remove(k)
#print(templist,trylist)
for l in range(len(templist)):
for m in range(len(trylist)):
if templist[l] == trylist[m]:
q = q + 1
print(str(p)+'A'+str(q)+'B')
送出測試:
送出解答:
資料來源:
1.高中生解題系統
2.a291: nAnB problem
ZeroJudge python解答:a694. 吞食天地二ZeroJudge python解答:a738. 最大公约数