Skip to content

Instantly share code, notes, and snippets.

@pcchou
Last active April 7, 2022 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcchou/56037d280d4ecaebdd78837e20f2bf41 to your computer and use it in GitHub Desktop.
Save pcchou/56037d280d4ecaebdd78837e20f2bf41 to your computer and use it in GitHub Desktop.
3035 bearrrrrrrro的綽號們
n = int(input())
dic = {}
for _ in range(n):
inputs = input().split()
op = int(inputs[0])
if op == 1:
nickname = inputs[1]
if nickname in dic:
dic[nickname] += 1
else:
dic[nickname] = 1
elif op == 2:
nickname = inputs[1]
if nickname in dic:
dic[nickname] -= 1
if dic[nickname] == 0:
del dic[nickname]
elif op == 3:
ans = list(dic.items())
ans.sort()
for key, value in ans:
print(key, value)
elif op == 4:
print(len(dic))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment