2015年刷题目录
2015年12月
201512-1 数位之和
题目链接:
http://118.190.20.162/view.page?gpid=T37
代码:
n = input()
sum_n = 0
for i in range(len(n)):
sum_n += int(n[i])
print(sum_n)
201512-2 消除类游戏
题目链接:
http://118.190.20.162/view.page?gpid=T36
代码:
n,m = map(int,input().split())
info = []
tag = [[1 for i in range(m)] for j in range(n)]
for i in range(n):
info.append(list(map(int,input().split())))
for i in range(n):
count = 0
for j in range(1,m):
if info[i][j-1] == info[i][j]: #检查同一行
count += 1
if count == 2:
tag[i][j] = 0
tag[i][j-1] = 0
tag[i][j-2] = 0
elif count > 2:
tag[i][j] = 0
else:
count = 0
for j in range(m):
count_l = 0
for i in range(1,n):
if info[i-1][j] == info[i][j]:#检查列
count_l += 1
if count_l == 2:
tag[i][j] = 0
tag[i-1][j] = 0
tag[i-2][j] = 0
elif count_l > 2:
tag[i][j] = 0
else:
count_l = 0
for i in range(n):
for j in range(m):
if j == m-1:
print(tag[i][j] and info[i][j])
else:
print(tag[i][j] and info[i][j],end=" ")
易错点需注意点:注意and前后都为真时结果返回第二个值。
2015年09月
201509-1 数列分段
题目链接:
http://118.190.20.162/view.page?gpid=T32
代码:
n = int(input())
l = list(map(int,input().split()))
count = 0
for i in range(1,n):
if l[i] != l[i-1]:
count += 1
print(count+1)
易错点需注意点:
201509-2 日期计算
题目链接:
http://118.190.20.162/view.page?gpid=T31
代码:
def isRun(year):
if year%400 == 0:
return 1
elif year%4==0 and year%100 != 0:
return 1
else:
return 0
days = [31,28,31,30,31,30,31,31,30,31,30,31]
year = int(input())
days[1] += isRun(year)
d = int(input())
month,day = 0,0
while d != 0:
if d > days[month]:
d -= days[month]
month += 1
else:
day = d
d -= day
print(month+1)
print(day)
易错点需注意点:如果刚好是月末最后一天,直接输出即可。
2015年03月
201503-1 图像旋转
题目链接:
http://118.190.20.162/view.page?gpid=T27
代码:
n,m = map(int,input().split())
info = []
new_info = [[0 for i in range(n)] for j in range(m)]
for i in range(n):
l = list(map(int,input().split()))
for j in range(m):
new_info[j][i] = l[j]
new_info = new_info[::-1]
for i in range(m):
print(" ".join(map(str,new_info[i])))
易错点需注意点:
201503-2 数字排列
题目链接:
http://118.190.20.162/view.page?gpid=T26
代码:
n = int(input())
l = list(map(int,input().split()))
d = {}
s_l = set(l)
for x in l:
d[x] = l.count(x)
d = sorted(d.items(),key=lambda x:(x[1],-x[0]),reverse=True)
for i in range(len(d)):
print("{0} {1}".format(d[i][0],d[i][1]))