洛谷 P5587 打字练习 python

版本一:正常写

版本二:改成函数形式了

#版本1
text = []
inp = []
total = 0

while True:
    st = input()
    while "<" in st:
        index = st.find("<")
        if index != 0:
            st = st[0:index-1]+st[index+1:]
        else:
            st = st[1:]
    if st == "EOF":
        break
    text.append(list(st))

while True:
    st = input()
    while "<" in st:
        index = st.find("<")
        if index != 0:
            st = st[0:index-1]+st[index+1:]
        else:
            st = st[1:]
    if st == "EOF":
        break
    inp.append(list(st))

time = int(input())
minn = time/60

for i in range(min(len(text),len(inp))):
    for  j in range(min(len(text[i]),len(inp[i]))):
        if text[i][j] == inp[i][j]:
            total +=1

print(round(total/minn))
#round(number,digits)保留number四舍五入到第digits位
#版本2
def fun(res):
    while True:
        st = input()
        while "<" in st:
            index = st.find("<")#如果同时有多个<,st.find会返回找到的第一个<的下标
            if index != 0:
                st = st[0:index-1]+st[index+1:]
            else:
                st = st[1:]
        if st == "EOF":
            break 
        res.append(list(st))   

if __name__ == "__main__":
    text = []
    inp = []
    total = 0    
    fun(text)
    fun(inp)
    time = int(input())
    minn = time/60
    for i in range(min(len(text),len(inp))):
        for  j in range(min(len(text[i]),len(inp[i]))):
            if text[i][j] == inp[i][j]:
                total +=1
    #round(number,digits)保留number四舍五入到第digits位
    print(round(total/minn))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值