天梯赛练习集-L1-041到L1-050–python

文章目录

  • Python
    • L1-041 寻找250
    • L1-042 日期格式化
    • L1-043 阅览室
    • L1-044 稳赢
    • L1-045 宇宙无敌大招呼
    • L1-046 整除光棍
    • L1-047 装睡
    • L1-048 矩阵A乘以B
    • L1-049 天梯赛座位分配
    • L1-050 倒数第N个字符串

Python

L1-041 寻找250

n = input().split()
print(n.index("250") + 1)

L1-042 日期格式化

n = input()
print(n[6:10],"-",n[0:5],sep='')

L1-043 阅览室

注意多次借,需要覆盖前面的借。
还了记得删除

n = int(input())
for i in range(n):
    a = {}
    t = 0
    times = 0
    while 1:
        s = input().split()
        if s[0] == "0":
            if t == 0:
                print(0,0)
            else:
                print(t,"%d"%(round(times/t)))
            break
        if s[1] == "S":
            tt = s[2].split(":")
            a[s[0]] = int(tt[0])*60+int(tt[1])
        else:
            if s[0] in a:
                t += 1
                tt = s[2].split(":")
                times +=int(tt[0])*60+int(tt[1])-a[s[0]]
                del a[s[0]]

L1-044 稳赢

n = int(input())
list = ['ChuiZi','Bu','JianDao','ChuiZi']
i = 0
s = input()
while s != "End":
    if i == n:
        i = -1
        print(s)
    else:
        print(list[list.index(s)+1])
    i += 1
    s = input()

L1-045 宇宙无敌大招呼

print('Hello',input())

L1-046 整除光棍

n = int(input())
s = "1"
while True:
    if int(s) % n == 0:
        print(int(s)//n,len(s))
        break
    else:
        s += "1"

L1-047 装睡

n = int(input())
for i in range(n):
    s = input().split()
    if not 15<=int(s[1])<=20 or not 50<=int(s[2])<=70:
        print(s[0])

L1-048 矩阵A乘以B


ra,ca = map(int, input().split())
a = []
for i in range(ra):
    a.append(list(map(int, input().split())))
rb,cb = map(int, input().split())
b = []
for i in range(rb):
    b.append(list(map(int, input().split())))
if ca == rb:
    c = []
    for i in range(ra):
        c.append([])
        for j in range(cb):
            n  = 0
            for z in range(ca):
                n += a[i][z] * b[z][j]
            c[i].append(str(n))
    print(ra,cb)
    for i in range(len(c)):
        print(" ".join(c[i]))
else:
    print("Error: %d != %d"%(ca,rb))

L1-049 天梯赛座位分配

n = int(input())
a = list(map(int, input().split()))
num = 0
for i in range(n):
    num += a[i]
num *= 10
ans = [[] for i in range(n)]
li = [i for i in range(n)]
j = 0
i = 1
while i <= num:
    if len(li) == 1:
        num += num - i
        while i <= num:
            k = li[0]
            ans[k].append(i)
            i+=2
        break
    k = li[j]
    ans[k].append(i)
    i += 1
    if len(ans[k]) == a[k]*10:
        li.remove(k)
        if j >= len(li):
            j = 0
        continue
    if j >= len(li) - 1:
        j = 0
    else:
        j += 1
    
for i in range(n):
    print("#%d"%(i+1))
    m = ans[i]
    for j in range(len(m)):
        print(m[j],end="")
        if j % 10 == 9:
            print()
        else:
            print(" ",end="")

L1-050 倒数第N个字符串

l,n = map(int,input().split())
a = [27 for i in range(l)]
n-=1
b=[0 for i in range(l)]
for i in range(l):
    b[i] = n%26
    n//=26 
b.reverse()
for i in range(l):
    print(chr(a[i]-b[i]+95),end='')

你可能感兴趣的:(算法题,python,java,开发语言,算法)