人生苦短,我用python
https://pintia.cn/problem-sets/1111652100718116864/problems/type/1
浙大python习题\第5章\1.输出星期名缩写.py
dic = {1:"Mon",2:"Tue",3:"Wed",4:"Thu",5:"Fri",6:"Sat",7:"Sun"}
n = int(input())
print(dic[n])
浙大python习题\第5章\2.图的字典表示.py
n=int(input())
num=0
sum=0
for i in range(n):
dic=eval(input())
for j in dic:
temp=dic[j]
for key in temp:
num+=1
sum+=temp[key]
print("{:d} {:d} {:d}".format(n,num,sum))
浙大python习题\第5章\3.用字典实现四则运算.py
a = int(input())
way = input()
b = int(input())
if way == '/' and b == 0:
print('divided by zero')
else:
dic = {'+':a+b,'-':a-b,'*':a*b,'/':a/b}
print('{:.2f}'.format(dic[way]))
浙大python习题\第5章\4.用集合分析活动投票.py
s=set(map(int,input().split(",")))
for i in range(6,11):
if i not in s:
print(i,end=' ')
浙大python习题\第5章\5.统计字符出现次数.py
print(input().count(input()))
浙大python习题\第5章\6.统计工龄.py
n = int(input())
list = list(map(int, input().split()))
set = sorted(set(list))
for i in set:
s=list.count(i)
print(f'{i}:{s}')
浙大python习题\第5章\7.列表去重.py
s1 = [11, 2, 3, 4, 3]
s2 = list(set(s1))
s2.sort(key = s1.index)
print(*s2)
浙大python习题\第5章\8.求能被3,5,7整除的个数.py
a, b = map(int,input().split())
c = set()
for i in range(a,b+1):
if i%3 == 0 and i%5 == 0 and i%7 == 0 :
c.add(i)
print(len(c))
浙大python习题\第5章\9.求矩阵鞍点个数.py
n=eval(input())
ls=[]
for i in range(n):
a=list(map(int,input().split()))
ls.append(a)
q=0
for i,j in enumerate(ls):
for m,l in enumerate(j):
ld=[ls[k][m] for k in range(n)]
if l==max(j) and l ==min(ld):
q+=1
浙大python习题\第5章\10.给定目标,求两数之和.py
value = list(map(int, input().split(",")))
n = eval(input())
keys = [x for x in range(len(value))]
d = dict(zip(value, keys))
for i, v in d.items():
if(n - i) in d.keys():
print(v, d[n-i])
exit(0)
print("no answer")
浙大python习题\第5章\11.字典合并.py
a, b = eval(input()), eval(input())
c = [i for i in a.keys() if i in b.keys()]
for i in c:
b[i] = a[i] + b[i]
a.update(b)
c=str(dict(sorted(a.items(), key=lambda x: x[0] if type(x[0]) == int else ord(x[0]))))
c = c.replace(' ', '')
c = c.replace("'", '"')
print(c)