python 团体程序设计天梯赛L1合集(持续更新)

56 篇文章 2 订阅

L1-001 Hello World

Hello World!

print("Hello World!")


L1-002 打印沙漏

*****
***
*
***
*****


19 *

*****
***
*
***
*****


2

a = input().split()
n = int(a[0])
# 计算最长一行的字符个数
n = n - 1
line = 3
sum1 = 1
while n > 2 * line:
n = n - line * 2
sum1 = sum1 + line * 2
line = line + 2
line = line - 2         # line存储最长的字符个数

res = []
j = line
while j > 1:            # 注意没有等于1, 1的情况在后面输出
s = " " * ((line - j)//2) + a[1] * j        # 右边不能有空格，因此不能用str.center()方法来格式化
print(s)
j = j - 2
j = 1
while j <= line:
s = " " * ((line - j)//2) + a[1] * j
print(s)
j = j + 2

print(int(a[0]) - sum1)



L1-003 个位数统计

​k−1
​​ 10
​k−1
​​ +⋯+d
​1
​​ 10
​1
​​ +d
​0
​​ (0≤d
​i
​​ ≤9, i=0,⋯,k−1, d
​k−1
​​ >0)，请编写程序统计每种不同的个位数字出现的次数。例如：给定 N=100311，则有 2 个 0，3 个 1，和 1 个 3。

100311

0:2
1:3
3:1

n = input()
s = {}
for i in n:
if i in s:
s[i] = s[i] + 1
else:
s[i] = 1
for i in sorted(s):
print(i, s[i], sep=":")


L1-004 计算摄氏温度

150

Celsius = 65

s=input()
f=int(5*(int(s)-32)/9)
print("Celsius = "+str(f))


L1-005 考试座位号

4
3310120150912233 2 4
3310120150912119 4 1
3310120150912126 1 3
3310120150912002 3 2
2
3 4

3310120150912002 2
3310120150912119 1

N=int(input())
a=[]
b=[]
c=[]
for i in range(N):
t=input().split()
a.append(t[0])
b.append(int(t[1]))	#因为我们要查询它在列表中位置，所以得用int()
c.append(t[2])
t=int(input())
d=input().split()
for i in d:
t=b.index(int(i))	#通过index()方法找到位置
print(a[t],c[t])


L1-006 连续因子

​31
​​ ）。

630

3
567

import math

n = int(input())
m = 0
mm = -1
for i in range(2, int(math.sqrt(n))+1):
if n % i == 0:
j = i + 1
t = n / i
while t % j == 0:
t = t / j
j = j + 1
if j - i > m:
m = j - i
mm = i

if mm != -1:        # 可能有质数的情况
print(m)
s = str(mm)
for i in range(mm + 1, mm + m):
s = s + "*" + str(i)
print(s)
else:
print(1)
print(n)


L1-007 念数字

0: ling
1: yi
2: er
3: san
4: si
5: wu
6: liu
7: qi
8: ba
9: jiu

-600

fu liu ling ling

dict={'-':'fu','0':'ling','1':'yi','2':'er','3':'san','4':'si','5':'wu',
'6':'liu','7':'qi','8':'ba','9':'jiu'}
a=input()
for i in range(len(a)-1):
print(dict[a[i]],end=" ")
print(dict[a[len(a)-1]])


L1-008 求整数段和

-3 8

-3 -2 -1 0 1
2 3 4 5 6
7 8
Sum = 30

a=input().split()
sum=0
cnt=0
for i in range(int(a[0]),int(a[1])+1):
sum=int(i)+sum
if cnt%5==0 and cnt!=0 :
print()
print("%5d"%i,end="")
cnt=cnt+1
print("\nSum = %d"%sum)



L1-009 N个数求和

5
2/5 4/15 1/30 -2/60 8/3

3 1/3

2
4/3 2/3

2

3
1/3 -1/6 1/8

7/24

# 又是为大数舒服的一题
def gcd(a, b):
while b != 0:
c = a % b
a = b
b = c
return a

n = int(input())
s = input().split()

mu = 1
for i in s:
i = i.split("/")
mu = mu * int(i[1])
zi = 0
for i in s:
i = i.split("/")
zi = zi + int(i[0]) * mu // int(i[1])

t = gcd(abs(zi), mu)
zi = zi // t
mu = mu // t

if zi == 0:         # 为零的情况,测试点6
print(0)

flag = False
if abs(zi) >= mu:       # 分子为负数的情况，测试点4.5
print(zi//mu, end="")
flag = True

if abs(zi)%mu != 0:
if flag:
print(end=" ")
if zi < 0:
print(end="-")
zi = abs(zi)
print(zi%mu, mu,sep="/")



L1-010 比较大小

4 2 8

2->4->8

a=input().split()
b=[]
for i in a:
b.append(int(i))
b.sort()
for i in b[0:len(b)-1]:
print(i,end="->")
print(b[len(b)-1])


L1-011 A-B

​4
​​ ，并且保证每个字符串都是由可见的ASCII码和空白字符组成，最后以换行符结束。

I love GPLT! It’s a fun game!
aeiou

I lv GPLT! It’s fn gm!

a = input()
b = input()
for i in b:
# str.replace(old, new, max) 用新的字符串替换旧的字符串，max是最大替换数量
a = a.replace(i, "")
print(a)



L1-012 计算指数

5

2^5 = 32

n=int(input())
print("2^"+str(n)+" = "+str(pow(2,n)))


L1-013 计算阶乘和

3

9

n=int(input())
ans=0
sum=1
for i in range(1,n+1):
sum=sum*i
ans=ans+sum
print(ans)


L1-014 简单题

This is a simple problem.

print("This is a simple problem.")


L1-015 跟奥巴马一起画方块

10 a

aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa
aaaaaaaaaa

t=input().split()
n=int(t[0])
for i in range(int(n/2+0.5)):#四舍五入取整
for j in range(n):
print(t[1],end="")
print()


L1-016 查验身份证

Z：0 1 2 3 4 5 6 7 8 9 10
M：1 0 X 9 8 7 6 5 4 3 2

4
320124198808240056
12010X198901011234
110108196711301866
37070419881216001X

12010X198901011234
110108196711301866
37070419881216001X

2
320124198808240056
110108196711301862

All passed

M = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']         # 这里用字符列表，因为有X，比较起来会比较方便
w = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
n = int(input())
a = 0
ans = []
for i in range(n):
s = input()
cnt = 0
sum = 0
flag = True
for j in s[:-1]:        # 最后一个字符不处理，-1代表最后一个，str[]切片范围：左闭右开，
if j.isdigit():     # 若前17个有非数字也算错误，即不处理,不然会有一个测试点过不去
sum = sum + w[cnt] * int(j)
cnt = cnt + 1
else:
flag = False
break
if flag and M[sum%11] == s[17]:
a = a + 1
else:
ans.append(s)
if a == n:
print("All passed")
else:
for i in ans:
print(i)



L1-017 到底有多二

-13142223336

81.82%

s=input()
n=s.count("2")
if s[0]=='-':
ans = float(n / (len(s)-1)) * 100
ans *= 1.5
else :
ans = float(n / len(s) ) * 100
if int(s[-1])%2==0:
ans*=2
print("%.2f"%ans+"%")


L1-018 大笨钟

Only hh:mm. Too early to Dang.

19:05

DangDangDangDangDangDangDangDang

07:05

Only 07:05. Too early to Dang.

s=input()
clock=s.split(':')
up=0    #不要忘了，不然错误返回非零值
if int(clock[1])>0 :
up=1
if int(clock[0])>12 :
sum=int(clock[0])-12+up
for i in range(sum):
print("Dang",end="")
else:
print("Only "+s+".  Too early to Dang.")



L1-019 谁先倒

1 1
6
8 10 9 12
5 10 5 10
3 8 5 12
12 18 1 13
4 16 12 15
15 1 1 16

A
1

n=input().split()
a=int(n[0])
b=int(n[1])
sum=int(input())
for i in range(sum):
s=input().split()
if int(s[0])+int(s[2])==int(s[1]) and int(s[0])+int(s[2])!=int(s[3]):
a=a-1
if int(s[0])+int(s[2])!=int(s[1]) and int(s[0])+int(s[2])==int(s[3]):
b=b-1
if(a<0):
print("A")
print(int(n[1])-b)
break
if(b<0):
print("B")
print(int(n[0])-a)
break


L1-020 帅到没朋友

3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
8
55555 44444 10000 88888 22222 11111 23333 88888

10000 88888 23333

3
3 11111 22222 55555
2 33333 44444
4 55555 66666 99999 77777
4
55555 44444 22222 11111

No one is handsome

n = int(input())
friend = set()          # 创建空集合
for i in range(n):
s = input().split()
if int(s[0]) != 1:
friend.update(s)        # 用update方法添加列表到集合里
m = int(input())
all_f = input().split()
f_ed = {}           # 这里要用字典，不能用列表，不然会超时。
flag = True
for i in all_f:
if i not in friend and i not in f_ed:
f_ed[i] = 1
if flag:
print(i, end="")
else:
print("", i, end="")
flag = False
if flag:
print("No one is handsome")


L1-021 重要的话说三遍

I’m gonna WIN!
I’m gonna WIN!
I’m gonna WIN!

for i in range(3):
print("I'm gonna WIN!")


L1-022 奇偶分家

9
88 74 101 26 15 0 34 22 77

3 6

n=int(input())
ans1=0
ans2=0
t=input().split()
for i in range(n):
if int(t[i])%2==1:
ans1+=1
else :
ans2+=1
print(ans1,ans2)


L1-023 输出GPLT

pcTclnGloRgLrtLhgljkLhGFauPewSKgt

GPLTGPLTGLTGLGLL

s = input().upper()         # 将输入的字符串转成大写
a = {}
demo_upper = ['G', 'P', 'L', 'T']
cnt = 0
for i in s:
if i in demo_upper:
if i in a:
a[i] = a[i] + 1
else:
a[i] = 1
cnt = cnt + 1

while cnt > 0:
for i in demo_upper:
if i in a and a[i] != 0:        # 注意这里要先判断是否在字典里
print(i, end="")
a[i] = a[i] - 1
if a[i] == 0:
cnt = cnt - 1



L1-024 后天

3

5

n = 2 + int(input())
print(n % 8 + int(n / 8))


L1-025 正整数A+B

123 456

123 + 456 = 579

22. 18

? + 18 = ?

-100 blabla bla…33

? + ? = ?

a=input().split(' ',1)  #以第一个空格为分界
flag=True
if a[0].isdigit() and a[0].count(".")==0 and int(a[0])>0 and int(a[0])<=1000:   #先判断是不是数字，再判断是不是整数，最后再判断范围
print(a[0]+" + ",end="")
else:
print("? + ",end="")
flag=False
if a[1].isdigit() and a[1].count(".")==0 and int(a[1])>0 and int(a[1])<=1000:
print(a[1]+" = ",end="")
else:
print("? = ",end="")
flag=False
if flag:
print(int(a[0])+int(a[1]))
else:
print("?")



L1-026 I Love GPLT

I

L
o
v
e

G
P
L
T

s = """I

L
o
v
e

G
P
L
T"""
print(s)


L1-027 出租

18013820100

int[] arr = new int[]{8,3,2,1,0};
int[] index = new int[]{3,0,4,3,1,0,2,4,3,4,4};

num = input()
a = {}
for i in range(10):
a[i] = 0
for i in num:
a[int(i)] = 1
arr = []
for i in range(9, -1, -1):
if a[i] == 1:
arr.append(i)
num_index = []
for i in num:
num_index.append(arr.index(int(i)))

# 输出
s1 = "int[] arr = new int[]{"
for i in arr[:-1]:
s1 = s1 + str(i) + ","
s1 = s1 + str(arr[-1]) + "};"
print(s1)
s2 = "int[] index = new int[]{"
for i in num_index[:-1]:
s2 = s2 + str(i) + ","
s2 = s2 + str(num_index[-1]) + "};"
print(s2)



L1-028 判断素数

​31
​​ 的需要判断的正整数。

2
11
111

Yes
No

import math

def isPrime(a):
flag=True
for i in range(2,int(math.sqrt(a))):
if a%i==0:
flag=False
break;
return flag

n=int(input())
for i in range(n):
s=int(input())
if s!=1 and isPrime(s): #注意特判1
print("Yes")
else:
print("No")



L1-029 是不是太胖了

169

124.2

n = int(input()) - 100
print("%.1f"%(n*1.8))


L1-030 一帮一

“一帮一学习小组”是中小学中常见的学习组织方式，老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作，即在得到全班学生的排名后，在当前尚未分组的学生中，将名次最靠前的学生与名次最靠后的异性学生分为一组。

8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda

Amy Jack
Tom Linda
Bill Maya
Cindy John

n=int(input())
s=[]
boy=[]
girl=[]
for i in range(n):
t=input()
s.append(t)
t=t.split()
if t[0]=='0':
girl.append(t[1])
else:
boy.append(t[1])
n=int(n/2)
num1=0  #女生出现次数
num2=0  #男生出现次数
for i in range(n):
t=s[i].split()
if t[0]=='0':
print(girl[num1],boy[n-num1-1],sep=" ")     #第num1+1个女生配倒数第num1+1个男生
num1+=1
else:
print(boy[num2],girl[n-num2-1],sep=" ")
num2+=1


L1-031 到底是不是太胖了

3
169 136
150 81
178 155

You are wan mei!
You are tai shou le!
You are tai pang le!

n=int(input())
for i in range(n):
s=input().split()
sta=(int(s[0])-100)*0.9     #标准体重
real=int(s[1])/2
per=(sta-real)*100/(sta)        #为负说明真实比标准大
#    print(str(i),sta,real,per,sep=" ")
if per>=10:
print("You are tai shou le!")
elif per<=-10:
print("You are tai pang le!")
else:
print("You are wan mei!")


​4
​​ ）和一个字符，分别是填充结果字符串的长度和用于填充的字符，中间以1个空格分开。第二行给出原始的非空字符串，以回车结束。

15 _
I love GPLT

____I love GPLT

4 *
this is a sample for cut

cut

a = input().split()
s = input()
if len(s) < int(a[0]):
s = a[1] * (int(a[0]) - len(s)) + s
else:
s = s[len(s)-int(a[0]):]
print(s)


L1-033 出生年

1988 4

25 2013

1 2

0 0001

def check(s,n):
s=str(s)
for i in range(4-len(s)):       #补零
s="0"+s
cnt=0
for i in range(10):     #千万不能range(9)，这样不会到9
if s.count(str(i))>=1:
cnt=cnt+1
if cnt==n:      #只有相同才正确
return True
else:
return False

t=input().split()
year=int(t[0])
n=int(t[1])
ans=year
while(True):
if check(ans,n):
break;
else:
ans=ans+1
print(ans-year,"%04d"%ans,sep=" ")      #年份按格式输出



L1-034 点赞

​1
​​ ⋯F
​K
​​ ”，其中1≤K≤10，F
​i
​​ （i=1,⋯,K）是特性标签的编号，我们将所有特性标签从1到1000编号。数字间以空格分隔。

4
3 889 233 2
5 100 3 233 2 73
4 3 73 889 2
2 233 123

233 3

n=int(input())
sum={}      #用字典来记录特征与出现次数
for i in range(n):
t=input().split()
for j in t[1:]:     #从第二个开始
if j in sum:
sum[j]=sum[j]+1
else:
sum[j]=1
t=max(sum.values())     #获取最大的出现次数
ans=0
for key,value in sum.items():
if value==t and ans<int(key):
ans=int(key)
print(ans,t,sep=" ")



L1-035 情人节

GaoXZh
Magi
Einst
Quark
LaoLao
FatMouse
ZhaShen
fantacy
latesum
SenSen
QuanQuan
whatever
whenever
Potaty
hahaha
.

Magi and Potaty are inviting you to dinner…

LaoLao
FatMouse
whoever
.

FatMouse is the only one for you…

LaoLao
.

Momo… No one is for you …

cnt=0
ans=[]
while(True):
s=input()
if s=='.':
break;
cnt=cnt+1
if cnt==2:
ans.append(s)
if cnt==14:
ans.append(s)
if len(ans)==0:
print("Momo... No one is for you ...")
elif len(ans)==1:
print(ans[0]+" is the only one for you...")
else:
print(ans[0]+" and "+ans[1]+" are inviting you to dinner...")


L1-036 A乘以B

-8 13

-104

n=input().split()
print(int(n[0])*int(n[1]))


L1-037 A除以B

-1 2

-1/2=-0.50

1 -3

1/(-3)=-0.33

5 0

5/0=Error

n=input().split()
print(int(n[0]),end="")
if int(n[1])<0:
print("/(" + n[1] + ")=" + "%.2f" % (int(n[0]) / int(n[1])))
elif int(n[1])>0:
print("/" + n[1] + "=" + "%.2f" % (int(n[0]) / int(n[1])))
else:
print("/" + n[1] + "=" + "Error")


L1-038 新世界

Hello World
Hello New World

print("Hello World")
print("Hello New World")


L1-039 古风排版

4
This is a test case

asa T
st ih
e tsi
ce s

n = int(input())
s = input()
a = len(s) // n;
if a * n < len(s):
a = a + 1
s = s + " " * (a * n - len(s))

for i in range(0, n):
for j in range(a-1, -1, -1):
print(s[j*n+i], end="")
print()



L1-040 最佳情侣身高差

2
M 1.75
F 1.8

1.61
1.96

n=int(input())
s=[]
for i in range(n):
s.append(input())
for i in s:
t=i.split()
if t[0]=="F":
print("%.2f"%(float(t[1])*1.09))
else:
print("%.2f"%(float(t[1])/1.09))



L1-041 寻找250

888 666 123 -233 250 13 250 -222

5

n=input().split()
cnt=0
for i in n:
if int(i)==250:
print(cnt+1)
break;
cnt=cnt+1


L1-042 日期格式化

03-15-2017

2017-03-15

s=input().split("-")    #以-为分隔符分割字符串
print(s[2],s[0],s[1],sep="-")


L1-043 阅览室

3
1 S 08:10
2 S 08:35
1 E 10:00
2 E 13:16
0 S 17:00
0 S 17:00
3 E 08:10
1 S 08:20
2 S 09:00
1 E 09:20
0 E 17:00

2 196
0 0
1 60

def calculate_time(start_time, end_time):
s1 = start_time.split(':')
s2 = end_time.split(':')
a1 = int(s1[0]) * 60 + int(s1[1])
a2 = int(s2[0]) * 60 + int(s2[1])
return a2 - a1

n = int(input())
cnt = 0
book = {}
book_num = 0
book_time = 0
while cnt < n:
s = input().split()
if s[0] == '0':
cnt = cnt + 1
if book_num != 0:
book_time = int(book_time / book_num + 0.5)
print(book_num, book_time, sep=" ")
# 重置
book.clear()
book_num = 0
book_time = 0
continue
if s[1] == 'S':
book[s[0]] = s[2]
else:
if s[0] in book and book[s[0]] != "-1":      # 判断书是否被借 和 是否已还
book_time = book_time + calculate_time(book[s[0]], s[2])
book_num = book_num + 1
book[s[0]] = "-1"



L1-044 稳赢

2
ChuiZi
JianDao
Bu
JianDao
Bu
ChuiZi
ChuiZi
End

Bu
ChuiZi
Bu
ChuiZi
JianDao
ChuiZi
Bu

k=int(input())+1
win={"JianDao":"ChuiZi","ChuiZi":"Bu","Bu":"JianDao"}
ans=[]
cnt=0
while(True):
s=input()
cnt=cnt+1
if s=="End":
break;
if cnt%k!=0:
print(win[s])
else:
print(s)



L1-045 宇宙无敌大招呼

Mars

Hello Mars

s=input()
print("Hello "+s)


L1-046 整除光棍

31

3584229390681 15

n=int(input())
ans=1
cnt=1
while(True):
if ans%n==0:
print("%d" %(ans / n), cnt, sep = " ")        #若是'/'除法会在n=313时爆float，因此改为'//'Floor除法
break;
ans=ans*10+1
cnt=cnt+1


L1-047 装睡

4
Amy 15 70
Tom 14 60
Joe 18 50
Zoe 21 71

Tom
Zoe

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


L1-048 矩阵A乘以B

2 3
1 2 3
4 5 6
3 4
7 8 9 0
-1 -2 -3 -4
5 6 7 8

2 4
20 22 24 16
53 58 63 28

3 2
38 26
43 -5
0 17
3 2
-11 57
99 68
81 72

Error: 2 != 3

import numpy as np
a=input().split()
A=[]
B=[]
C=[]
for i in range(int(a[0])):
t=[int(item) for item in input().split()]
A.append(t)
b=input().split()
for i in range(int(b[0])):
t=[int(item) for item in input().split()]
B.append(t)
if int(a[1]) == int(b[0]):
C=np.dot(A,B)
print(a[0],b[1],sep=" ")
for i in C:
cnt=0
for j in i:
if cnt != len(i)-1:
print(j,end=" ")
cnt = cnt + 1
else:
print(j,end="")
print()
else:
print("Error:",a[1],"!=",b[0],sep=" ")



L1-050 倒数第N个字符串

​5
​​ ）。

3 7417

pat

1.初始为字符串“zzz”，第i位的减少量的基数为26i-1，类似进制转换，从z开始减，变化k位=='z'-k
2.要注意倒数第一位时变化量因位零，因此要把输入的数减一再计算。
3.ord('a')返回c的ASCLL码，chr(97)返回ASCLL码为97对应的字符。

a=input().split()
sum=int(a[1])-1     #注意要-1
s=""
for i in range(int(a[0])-1,0,-1):
k=sum//pow(26,i)        #‘//’向下取整返回整数
s=s+chr(ord("z")-k)     #算出第i位的字符
sum=sum%pow(26,i)
s=s+chr(ord("z")-sum)
print(s)


L1-051 打折

988 7

691.60

a=input().split()
print("%.2f"%(float(a[0])*int(a[1])*0.1))


L1-052 2018我们要赢

2018年天梯赛的注册邀请码是“2018wmyy”，意思就是“2018我们要赢”。本题就请你用汉语拼音输出这句话。

2018
wo3 men2 yao4 ying2 !

print("2018","wo3 men2 yao4 ying2 !",sep="\n")


L1-053 电子汪

2 1

Wang!Wang!Wang!

a=input().split()
for i in range(int(a[0])+int(a[1])):
print("Wang!",end="")


L1-054 福到了

“福”字倒着贴，寓意“福到”。不论到底算不算民俗，本题且请你编写程序，把各种汉字倒过来输出。这里要处理的每个汉字是由一个 N × N 的网格组成的，网格中的元素或者为字符 @ 或者为空格。而倒过来的汉字所用的字符由裁判指定。

1.我们可以采用嵌套列表，把每一行当成一个列表嵌套进总列表里。之后对总列表进行反转，最后一行变到第一行，但行内的顺序没有变，因为我们在取出时要进行第二次反转。
2.列表反转可以用列表内置的reverse()方法或者reversed函数。想了解它们两个区别点我！

def get_reverse(a):
b=[]
a.reverse()     #转置
for i in a:
b.append(list(reversed(i)))     #注意加list()
return b

def check(a,b):
for i in range(len(a)):
for j in range(len(b)):
if a[i][j] != b[i][j]:
return False
return True

n=input().split()
a=[]
for i in range(int(n[1])):
t=input()
t2=[]
for i in t:
t2.append(i)
for i in range(int(n[1])-len(t)):
t2.append(" ")
a.append(t2)
b=get_reverse(a)
if check(a,b):
print("bu yong dao le")
for i in b:
for j in i:
if j == '@':
print(n[0],end="")
else:
print(" ",end="")
print()


L1-055 谁是赢家

The winner is x: P1 + P2

327 129
1 0 1

The winner is a: 327 + 1

n=input().split()
m=input().split()
if int(n[0]) > int(n[1]):
num = 0
for i in m:
if i == '0':
num = num + 1
if num != 0:
print("The winner is a: ",n[0]," + ",num,sep="",end="")
else:
print("The winner is b: ",n[1]," + ",3,sep="",end="")
else:
num = 0
for i in m:
if i == '1':
num = num + 1
if num != 0:
print("The winner is b: ",n[1]," + ",num,sep="",end="")
else:
print("The winner is a: ",n[0]," + ",3,sep="",end="")



L1-056 猜数字

​4
​​ ）。随后 N 行，每行给出一个玩家的名字（由不超过8个英文字母组成的字符串）和其猜的正整数（≤ 100）。

7
Bob 35
Amy 28
James 98
Alice 11
Jack 45
Smith 33
Chris 62

22 Amy

n = int(input())
stu = []
stu_num = 0
for i in range(n):
s = input()
stu.append(s)
t = s.split()
stu_num = stu_num + int(t[1])
ave = stu_num // (n*2)
name = ""
num = 9999
for i in stu:
t = i.split()
if abs(int(t[1]) - ave) < num:
name = t[0]
num = abs(int(t[1]) - ave)
print(ave, name)


L1-057 PTA使我精神焕发

PTA shi3 wo3 jing1 shen2 huan4 fa1 !

print("PTA shi3 wo3 jing1 shen2 huan4 fa1 !")


L1-058 6翻了

“666”是一种网络用语，大概是表示某人很厉害、我们很佩服的意思。最近又衍生出另一个数字“9”，意思是“6翻了”，实在太厉害的意思。如果你以为这就是厉害的最高境界，那就错啦 —— 目前的最高境界是数字“27”，因为这是 3 个 “9”！

it is so 666 really 6666 what else can I say 6666666666

it is so 666 really 9 what else can I say 27

s = input()             # 可能有 66wrong66 类似的，不能用.count()单纯统计个数
temp = ""
num = 0
flag = False
for i in s:
if i == "6":        # 如果是 6 先不修改，统计 6串 长度
num = num + 1
flag = True     # 当前是 6串
else:               # 第 i 位肯定不是 6 ，因此肯定会加上第 i 位的字符，若前面是 6串 则判断修改 6串
if flag:
if num > 9:
temp = temp + "27"
elif num > 3:
temp = temp + "9"
else:
temp = temp + "6" * num     # "6" * num，表示让6重复num次，即恢复原状
temp = temp + i     # 不是else里
num = 0
flag = False
if flag:            # 如果字符串最后一个是 6，则需要再处理一次
if num > 9:
temp = temp + "27"
elif num > 3:
temp = temp + "9"
else:
temp = temp + "6" * num
print(temp)



L1-059 敲笨钟

5
xun zhang zhai ju lao diao chong, xiao yue dang lian gua yu gong.
tian sheng wo cai bi you yong, qian jin san jin huan fu lai.
xue zhui rou zhi leng wei rong, an xiao chen jing shu wei long.
zuo ye xing chen zuo ye feng, hua lou xi pan gui tang dong.
ren xian gui hua luo, ye jing chun shan kong.

xun zhang zhai ju lao diao chong, xiao yue dang lian qiao ben zhong.
Skipped
xue zhui rou zhi leng wei rong, an xiao chen jing qiao ben zhong.
Skipped
Skipped

def check(a, s):
if s[a-3:a] == 'ong':
return True
else:
return False

def notify(s):
a = s.find('.')
cnt = 0
for i in range(a, 0 ,-1):
if s[i] == ' ':
cnt = cnt + 1
if cnt == 3:
return s[0:i+1]         # 左闭右开
return s

n = int(input())
for i in range(n):
s = input()
index = s.find(',')
up = check(index, s)
index = s.find('.')
down = check(index, s)
if up and down:
s = notify(s) + "qiao ben zhong."
else:
s = "Skipped"
print(s)



L1-060 心理阴影面积

90 10

4000

a = input().split()
res = 5000 - 50 * (100 - int(a[0])) - 50 * int(a[1])
print(res)


L1-061 新胖子公式

100.1 1.74

33.1
PANG

65 1.70

22.5
Hai Xing

a = input().split()
res = float(a[0]) / (float(a[1]) * float(a[1]))
print("%.1f"%res)
if res > 25:
print("PANG")
else:
print("Hai Xing")



L1-062 幸运彩票

2
233008
123456

You are lucky!
Wish you good luck.

n = int(input())
for i in range(n):
s = input()
cnt = 0
sum = 0
for j in s:
cnt = cnt + 1
if cnt <= 3:
sum = sum + int(j)
else:
sum = sum - int(j)
if sum == 0:
print("You are lucky!")
else:
print("Wish you good luck.")


L1-063 吃鱼还是吃肉

4
0 130 23
1 129 27
1 130 30
0 128 27

ni li hai! duo chi rou!
duo chi yu! wan mei!
wan mei! shao chi rou!
duo chi yu! shao chi rou!

def check(sex, height, weight):
s = ""
if sex == "0":
if height < 129:
s = s + "duo chi yu!"
elif height > 129:
s = s + "ni li hai!"
else:
s = s + "wan mei!"
if weight < 25:
s = s + " duo chi rou!"
elif weight > 25:
s = s + " shao chi rou!"
else:
s = s + " wan mei!"
else:
if height < 130:
s = s + "duo chi yu!"
elif height > 130:
s = s + "ni li hai!"
else:
s = s + "wan mei!"
if weight < 27:
s = s + " duo chi rou!"
elif weight > 27:
s = s + " shao chi rou!"
else:
s = s + " wan mei!"
return s

n = int(input())
for i in range(n):
t = input().split()
print(check(t[0],int(t[1]),int(t[2])))


• 5
点赞
• 0
评论
• 20
收藏
• 一键三连
• 扫一扫，分享海报

04-20 41
03-18 606
03-29 344
09-30 1万+
03-04 599
04-02 774
04-15 226
04-14 294
03-27 2万+