201903-1 小中大
解答:
n = eval(input())
input_list = list(map(int,input().split()))
if n == 0:
print("0 0 0")
else:
if n %2 == 0:
mid = (input_list[n//2] + input_list[n//2 -1]) / 2
else:
mid = input_list[n//2]
a = max(input_list[0],input_list[-1])
i = min(input_list[0],input_list[-1])
if int(mid) == mid:
print(a,int(mid),i)
else:
print(f"{a} {mid:.1f} {i}")
感觉题目描述有错误,原来写的是mid+0.05,其实不是四舍五入
201903-2 二十四点
解答:
n = eval(input())
for i in range(n):
string24 = input()
string24 = string24.replace('x','*',3)
string24 = string24.replace('/','//',3)
if eval(string24) == 24:
print("Yes")
else:
print("No")
201909-1 小明种苹果
解答:
N,M = map(int,input().split())
reduce_apples = [0]*N
num = 0
for i in range(N):
apples = list(map(int,input().split()))
reduce_apples[i] = sum(apples[1:])
num += apples[0] + reduce_apples[i]
min_apple = min(reduce_apples)
index_apple = reduce_apples.index(min_apple)+1
print(num,index_apple,-min_apple)
201909-2 小明种苹果(续)
解答:
import sys
N = eval(sys.stdin.readline()) #苹果棵树
flag = [0]*N #记录苹果掉落棵树
num = 0
D = 0
E = 0
for i in range(N):
record = list(map(int,sys.stdin.readline().split()))
for x in range(2,record[0]+1):
if record[x] <= 0:
record[1] += record[x]
else:
if record[1] != record[x]:
flag[i] = 1
record[1] = record[x]
num += record[1]
for i in range(len(flag)):
if flag[i] == 1:
D += 1
if i == 0:
if (flag[i] + flag[i+1] + flag[len(flag)-1]) == 3:
E += 1
elif i == len(flag)-1:
if (flag[i] + flag[i - 1] + flag[0]) == 3:
E += 1
else:
if (flag[i-1] + flag[i] + flag[i+1]) == 3:
E += 1
print(num,D,E)
201912-1 报数
解答:
n = eval(input())
a = b = c = d = 0
num = 0
start = 1
while num < n:
if start % 7 == 0 or ('7' in str(start)):
if start % 4 == 1:
a += 1
elif start % 4 == 2:
b += 1
elif start % 4 == 3:
c += 1
else:
d += 1
else:
num += 1
start += 1
print(a)
print(b)
print(c)
print(d)
201912-2 回收站选址
解答:
n = eval(input())
point_dict = {}
num0 = [0]*5
for i in range(n):
x,y = map(int,input().split())
if x in point_dict.keys():
point_dict[x].append(y)
else:
point_dict[x] = [y] #键值对的值为列表
for key in point_dict.keys():
for i in point_dict[key]:
if (i+1) in point_dict[key] and (i-1) in point_dict[key]:
if i in point_dict.get(key-1,[]) and i in point_dict.get(key+1,[]):
num = 0
if (i-1) in point_dict.get(key-1,[]):
num += 1
if (i-1) in point_dict.get(key+1,[]):
num += 1
if (i+1) in point_dict.get(key-1,[]):
num += 1
if (i+1) in point_dict.get(key+1,[]):
num += 1
num0[num] += 1
for i in num0:
print(i)
# print(point_dict)