题解 | 特殊城市

特殊城市

https://www.nowcoder.com/practice/46f68af83db74b709a788dedb656c5f9

import sys
from collections import defaultdict

n, d, t = int(sys.stdin.readline()), defaultdict(int), 0
for _ in range(n):
    s, c = sys.stdin.readline().split()
    d[(s[:2],c)] += 1
for (a,b) in d.keys():
    if a<b and (b,a) in d.keys():
        t+=d[(a,b)]*d[(b,a)]
print(t)

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务