发票单统计

所属作业: hw6 数据结构: 字典

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
k = int(input())
name = {}
cat = {}
for i in range(k):
    x, y, z = input().split()
    z = float(z)
    if x not in name:
        name[x] = 0
    if y not in cat:
        cat[y] = 0
    name[x] += z
    cat[y] += z
list1 = sorted(name.keys())
list2 = sorted(cat.keys())
print(len(list1))
print(len(list2))
for i in list1:
    print(i, "%.2f" % name[i])
for i in list2:
    print(i, "%.2f" % cat[i])
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
k=int(input())
name={}
type={}
for i in range(k):
    x,y,z=input().split()
    z=float(z)
    if x not in name:
        name[x]=z
    else:
        name[x]+=z
    if y not in type:
        type[y]=z
    else:
        type[y]+=z
list1=list(name.keys())
list2=list(type.keys())
print(len(list1))
print(len(list2))
list1.sort()
list2.sort()
for i in list1:
    print(i,"%.2f"%name[i])
for i in list2:
    print(i,"%.2f"%type[i])