Problem:

Map: Delete

    For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that each key in $M$ must be unique.

  
insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.

  
get($key$): Print the value with the specified $key$. Print 0 if there is no such element.

  
delete($key$): Delete the element with the specified $key$.

Input

  The input is given in the following format.

$q$
$query_1$
$query_2$
:
$query_q$

Each query $query_i$ is given by

0 $key$ $x$

or

1 $key$

or

2 $key$

  where the first digits 0, 1 and 2 represent insert, get and delete operations respectively.

Output

  For each get operation, print an integer in a line.

Constraints

  
$1 \leq q \leq 200,000$

  
$1 \leq x \leq 1,000,000,000$

  
$1 \leq $ length of $key$ $ \leq 20$ 

  
$key$ consits of lower case letters

Sample Input 1

8
0 blue 4
0 red 1
0 white 5
1 red
1 blue
2 red
1 black
1 red

Sample Output 1

1
4
0
0



Sample input:
8
0 blue 4
0 red 1
0 white 5
1 red
1 blue
2 red
1 black
1 red


Sample output:
1
4
0
0

Submission status: Accepted

Solution code:
dict = {}
q = int(input())
for i in range(q):
    query, *val = input().split(' ')
    if query == '0':
        dict[val[0]] = int(val[1])
    elif query == '1':
        print(dict.get(val[0], 0))
    else:
        if val[0] in dict:
            dict.pop(val[0])

Submission status: Accepted

Solution code:
# AOJ ITP2_8_B: Map: Delete
# Python3 2018.6.24 bal4u

dict = {}
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = a[1]
	if a[0] == '0':	dict[ki] = int(a[2])
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	else:
		if ki in dict: dict[ki] = 0

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	map_delete
# CreatedDate:  2020-07-15 11:23:30 +0900
# LastModified: 2020-07-15 11:29:50 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    q = int(input())
    dictionary = {}
    for _ in range(q):
        command = list(input().split())
        if command[0] == '0':
            dictionary[command[1]] = int(command[2])
        elif command[0] == '1':
            if command[1] in dictionary.keys():
                print(dictionary[command[1]])
            else:
                print(0)
        else:
            if command[1] in dictionary.keys():
                del dictionary[command[1]]



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    n = int(input())
    ans = dict()
    for _ in range(n):
        q, key, *x = input().split()
        if q == "0":
            ans[key] = x[0]
        elif q == "1":
            if key in ans:
                print(ans[key])
            else:
                print(0)
        else:
            ans[key] = "0"


resolve()

Submission status: Accepted

Solution code:
D = {}
q = int(input())
for i in range(q):
    L = input().split()
    if L[0] == '0':
        key, x = L[1], L[2]
        D[key] = x
    elif L[0] == '1':
        key = L[1]
        if key in D.keys():
            print(D[key])
        else:
            print(0)
    else:
        key = L[1]
        if key in D.keys():
            del D[key]

Submission status: Accepted

Solution code:
import sys

d = {}

input()
for q in sys.stdin:
    q = q.split()
    if q[0] == '0':
        d[q[1]] = q[2]
    elif q[0] == '1':
        print(d.get(q[1], 0))
    else:
        if q[1] in d:
            del d[q[1]]

Submission status: Accepted

Solution code:

q = int(input())
dic = {}
for _ in range(q):
    op = list(input().split())
    if op[0]=='0':dic[op[1]] = op[2]
    elif op[0]=='1':
        print ( dic[op[1]] if op[1] in dic.keys() else 0)
    else:
        try :dic.pop(op[1])
        except :pass

Submission status: Accepted

Solution code:
dic = {}

for i in range(int(input())):
    order = list(input().split())

    if order[0] == "0":
        if order[1] in dic:
            dic[order[1]] = int(order[2])
        else:
            dic[order[1]] = int(order[2])
    elif order[0] == "1":
        if order[1] in dic:
            print(dic[order[1]])
        else:
            print(0)
    elif order[0] == "2":
        if order[1] in dic:
            dic.pop(order[1])

Submission status: Accepted

Solution code:
d = {}
for _ in range(int(input())):
    op, key, x = (input().split() + [''])[:3]
    if op == '0':
        d[key] = x
    elif op == '1':
        if d.get(key) == None:
            print(0)
        else:
            print(d[key])
    elif op == '2':
        if d.get(key) != None:
            del d[key]

Submission status: Accepted

Solution code:
dict = {}
q = int(input())
for i in range(q):
    a = list(input().split())
    if a[0] =="0":
        dict[a[1]] =int(a[2])
    elif a[0] =="1":
        print(dict[a[1]] if a[1] in dict else 0)
    else:
        if a[1] in dict: dict[a[1]] =0

Submission status: Accepted

Solution code:
q = int(input())
dict = {}
for i in range(q):
    a = input().split()
    if a[0] == "0":
        dict[a[1]] = a[2]
    elif a[0] == "1":
        if a[1] in dict:
            print(dict[a[1]])
        else:
            print(0)
    elif a[0] == "2":
        if a[1] in dict:
            del dict[a[1]]

Submission status: Accepted

Solution code:
q = int(input())
M = {}

for i in range(q):
    query, *inp = input().split()
    key = inp[0]

    # insert
    if query == "0":
        x = int(inp[1])
        M[key] = x

    # get
    elif query == "1":
        if key in M:
            print(M[key])
        else:
            print(0)

    # delete
    else:
        if key in M:
            del M[key]

Submission status: Accepted

Solution code:
dict = {}

q = int(input())

for i in range(q):
    line = input().split()
    if line[0] == "0":
        dict[line[1]]=int(line[2])
    elif line[0] == "1":
        if line[1] in dict.keys():
            print(dict[line[1]])
        else:
            print(0)
    elif line[0] == "2":
        if line[1] in dict.keys():
            dict.pop(line[1])

Submission status: Accepted

Solution code:
d = {}
for _ in range(int(input())):
	a = list(input().split())
	x = a[1]
	y = a[0]
	if y == "0":
		d[x] = a[2]
	elif y == "2":
		d[x] = 0
	else:
		print(d[x] if x in d else 0)

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    q = int(input())
    d = defaultdict(int)

    for _ in range(q):
        para = input().split()

        if para[0] == "0":
            d[para[1]] = int(para[2])

        elif para[0] == "1":
            print(d[para[1]])

        elif para[0] == "2":
            if para[1] in d.keys():
                del d[para[1]]
main()

Submission status: Accepted

Solution code:
import bisect

keys=[]

q=int(input())
d={}

def find(x):
    index=bisect.bisect_left(keys,x)
    if index==len(keys):
        return -1
    if keys[index]==x:
        return index
    else:
        return -1


for _ in range(q):
    query=input().split(" ")
    if query[0]=="0":
        if find(query[1])!=-1:
            pass
        else:
            bisect.insort_left(keys, query[1])
        d[query[1]]=query[2]
    elif query[0]=="1":
        if find(query[1])!=-1:
            print(d[query[1]])
        else:
            print(0)
    elif query[0]=="2":
        while find(query[1])>=0:
            keys.pop(find(query[1]))

Submission status: Accepted

Solution code:
n=int(input())
dic={}
for i in range(n):
    q,*args=map(str,input().split())
    key=args[0]
    val=args[0]
    if q=="0":
        val=int(args[1])
        dic[key]=val
    elif q=="1":
        if key in dic.keys():
            print(dic[key])
        else:
            print(0)
    else:
        if key in dic:
            dic.pop(key)
        else :
            None

Submission status: Accepted

Solution code:
#
n = int(input())
dic  = {}
a = [None] * n

for i in range(n):
    c, key, val = (input() + " 0").split()[:3]
    if c == "0":
        dic[key] = val
    elif c== "1":
        a[i] = dic.get(key,0)
    else:
        try:
            del dic[key]
        except KeyError:
            pass

[print(x) for x in a if x is not None]

Submission status: Accepted

Solution code:
M = {}
for i in range(int(input())):
    query = input().split()
    
    if query[0] == '0': M[query[1]] = query[2]
    elif query[0] == '1': 
        if query[1] in M: print(M[query[1]])
        else: print(0)
    else: M[query[1]] = 0

Submission status: Accepted

Solution code:
q = int(input())
dct = {}
for _ in range(q):
    cmmd = input().split( )
    if cmmd[0] == "0":
        dct[cmmd[1]] = int(cmmd[2])
    elif cmmd[0] == "1":
        try:
            print(dct[cmmd[1]])
        except:
            print(0)
    else:
        try:
            del(dct[cmmd[1]])
        except:
            pass

Submission status: Accepted

Solution code:
from collections import defaultdict


if __name__ == "__main__":
    num_query = int(input())
    d: defaultdict = defaultdict()

    for _ in range(num_query):
        op, *v = input().split()
        if ("0" == op):
            d[v[0]] = v[1]
        elif ("1" == op):
            if d.get(v[0]):
                print(d.get(v[0]))
            else:
                print(0)
        else:
            d[v[0]] = 0

Submission status: Accepted

Solution code:
dict = {}
q = int(input())
for i in range(q):
	a = list(input().split())
	ki = a[1]
	if a[0] == '0':	dict[ki] = int(a[2])
	elif a[0] == '1': print(dict[ki] if ki in dict else 0)
	else:
		if ki in dict: dict[ki] = 0

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Dictionary - Map: Delete
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_8_B&lang=jp

"""
d = dict()
for _ in range(int(input())):
    op, key, x = (input() + ' 1').split()[:3]
    if op == '0':
        d[key] = x
    elif op == '1':
        print(d.get(key, 0))
    elif key in d:
        del d[key]

Submission status: Accepted

Solution code:
import sys
n = int(input())
d = {}
lines = sys.stdin.readlines()
ans = [None] * n
for i in range(n):
    q, *arg = lines[i].split()
    if q == '0':
        d[arg[0]] = arg[1]
    elif q == '1':
        ans[i] = d[arg[0]] if arg[0] in d else 0
    elif q == '2':
        if arg[0] in d:
            del d[arg[0]]
 
[print(x) for x in ans if x is not None]

Submission status: Accepted

Solution code:
if __name__ == '__main__':

	n = int(input())
	d = {}

	for i in range(n):
		cmd = input().split()
		if cmd[0] == "0":
			d[cmd[1]] = cmd[2]
		elif cmd[0] == "1":
			if cmd[1] in d:
				print(d[cmd[1]])
			else:
				print("0")
		else:
			if cmd[1] in d:
				del d[cmd[1]]

Submission status: Accepted

Solution code:
M = {}

q = int(input())


for _ in range(q):
    
    command, *list_num = input().split()

    if   command == "0":
        # insert(key, x)
        key = list_num[0]
        x = int(list_num[1])
        M[key] = x            
    elif command == "1":
        # get(key)
        key = list_num[0]
        if key in M:
            print(M[key])
        else:
            print(0)
    elif command == "2":
        # delete(key)
        key = list_num[0]
        if key in M:
            del M[key]
    else:
        raise

Submission status: Accepted

Solution code:
import sys
n = int(input())
dic = {}
for i in range(n):
    a, b, *c = sys.stdin.readline().split()
    if a == '0':
        dic[b] = int(c[0])
    elif a == '1':
        print(dic[b] if b in dic else 0)
    else:
        if b in dic:
            del dic[b]

Submission status: Accepted

Solution code:
dict = {}
q = int(input())

for i in range(q):
    a = list(input().split())
    ki = a[1]
    if a[0] == '0':
        dict[ki] = int(a[2])
    elif a[0] == '1':
        print(dict[ki] if ki in dict else 0)
    else:
        if ki in dict:
            dict[ki] = 0

Submission status: Accepted

Solution code:
import bisect

D=[]
N=[]
count=0

def insert(D,N,count,key,x):
    y=bisect.bisect_left(D,key)
    if y<count and D[y]==key:
        N[y]=x
    else:
        D.insert(y,key)
        N.insert(y,x)
        count+=1
    return D,N,count

def get(D,N,count,key):
    y=bisect.bisect_left(D,key)
    if y<count and D[y]==key:
        print(N[y])
    else:
        print(0)

def erase(D,N,count,key):
    y=bisect.bisect_left(D,key)
    if y<count and D[y]==key:
        D.pop(y)
        N.pop(y)
        count-=1
    return D,N,count

q=int(input())
for i in range(q):
    query=list(map(str,input().split()))
    query[0]=int(query[0])
    if query[0]==0:
        D,N,count=insert(D,N,count,query[1],int(query[2]))
    elif query[0]==1:
        get(D,N,count,query[1])
    else:
        D,N,count=erase(D,N,count,query[1])

Submission status: Accepted

Solution code:
def main():
    q = int(input())
    d = {}
    for i in range(q):
        query = input()
        cmd = int(query[0])
        if cmd == 0:
            _, k, v = query.split(' ')
            v = int(v)
            d[k] = v
        elif cmd == 1:
            _, k = query.split(' ')
            print(d.get(k, 0))
        elif cmd == 2:
            _, k = query.split(' ')
            if k in d:
                del d[k]


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
dictionary = dict()

for i in range(int(input())):
    query = [i for i in input().split()]
    if query[0] == "0":
        dictionary.update({query[1]:query[2]})
        
    elif query[0] == "1":
        if not query[1] in dictionary.keys():
            print(0)
        else:
            print(dictionary[query[1]])    
    elif query[0] == "2":
        try:
            dictionary.pop(query[1])
        except:
            pass

Submission status: Accepted

Solution code:
import sys
n = int(input())
d = {}
lines = sys.stdin.readlines()
ans = [None] * n
for i in range(n):
    q, *arg = lines[i].split()
    if q == '0':    # insert
        d[arg[0]] = arg[1]
    elif q == '1':  # get
        ans[i] = d[arg[0]] if arg[0] in d else 0
    elif q == '2':  # delete
        if arg[0] in d:
            del d[arg[0]]

[print(x) for x in ans if x is not None]

Submission status: Accepted

Solution code:
q = int(input())

d = {}
for _ in range(q):
    command = list(map(str, input().split()))
    query = int(command[0])
    key = command[1]
    if query == 0:
        d[key] = int(command[2])
    elif query == 1:
        if key in d:
            print(d[key])
        else:
            print(0)
    else:
        if key in d:
            del d[key]

Submission status: Accepted

Solution code:
readline = open(0).readline
Q = int(readline())
ans = []
M = {}
get = lambda key, push=ans.append,get=M.get: push("%s\n" % get(key,"0"))
def delete(key):
    if key in M: del M[key]
C = [M.__setitem__, get, delete].__getitem__
for q in range(Q):
    t, *a = readline().split()
    C(int(t))(*a)
open(1, 'w').writelines(ans)

Submission status: Accepted

Solution code:
n = int(input())
M = {}
for i in range(n):
    query, *x = input().split()
    if query == "0":
        M[x[0]] = x[1]
    elif query == "1":
        if x[0] in M:
            print(M[x[0]])
        else:
            print(0)
    elif query == "2":
        M.pop(x[0], None)

Submission status: Accepted

Solution code:
from collections import defaultdict
n = int(input())
d = defaultdict(int)
for i in range(n):
  q = input().split()
  if q[0]=="0":
    d[q[1]] = int(q[2])
  elif q[0]=="1":
    print(d[q[1]])
  elif q[0]=="2":
    d[q[1]] = 0

Submission status: Accepted

Solution code:

class Node:

    def __init__(self, key, value):
        self.value = value
        self.key = key
        self.next = None


class HashMap:

    def __init__(self, _size=None):
        if _size is not None:
            assert _size > 0
        self._size = _size
        self._setsize(2)
        self.count = 0
        self.nodes = [None] * self.size

    def __getitem__(self, key):
        node = self.nodes[self.hash(key)]
        while node is not None and node.key != key:
            node = node.next
        if node is not None:
            return node.value
        else:
            raise IndexError('key {} not found in map'.format(key))

    def __setitem__(self, key, value):
        i = self.hash(key)
        node = self.nodes[i]
        if node is None:
            self.nodes[i] = Node(key, value)
            self.count += 1
        else:
            while node.next is not None and node.key != key:
                node = node.next
            if node.key == key:
                node.value = value
            else:
                node.next = Node(key, value)
                self.count += 1

        if self.count == self.size:
            self._resize(self.k + 1)

    def __delitem__(self, key):
        i = self.hash(key)
        node = self.nodes[i]
        if node is None:
            raise IndexError('key {} not found in map'.format(key))
        elif node.key == key:
            self.nodes[i] = node.next
            self.count -= 1
            return

        while node.next is not None and node.next.key != key:
            node = node.next
        if node.next is not None:
            node.next = node.next.next
            self.count -= 1
        else:
            raise IndexError('key {} not found in map'.format(key))

    def items(self):
        for node in self.nodes:
            n = node
            while n is not None:
                yield n.key, n.value
                n = n.next

    def __len__(self):
        return self.count

    def hash(self, key):
        return hash(key) % self.size

    def _setsize(self, k):
        if self._size is None:
            self.k = k
            self.size = 2 ** k - 1
        else:
            self.k = 0
            self.size = self._size

    def _resize(self, k):
        if self._size is not None:
            return
        nodes = self.nodes

        self._setsize(k)
        self.nodes = [None] * self.size
        self.count = 0
        for node in nodes:
            n = node
            while n is not None:
                self.__setitem__(n.key, n.value)
                n = n.next


def run():
    q = int(input())
    m = HashMap()

    for _ in range(q):
        command, *args = input().split()
        if command == '0':
            key = args[0]
            value = int(args[1])
            m[key] = value
        elif command == '1':
            key = args[0]
            try:
                print(m[key])
            except IndexError:
                print(0)
        elif command == '2':
            key = args[0]
            try:
                del m[key]
            except IndexError:
                pass
        else:
            raise ValueError('invalid command')


if __name__ == '__main__':
    run()

Submission status: Runtime Error

Solution code:
dict = {}
q = int(input())
for i in range(q):
    query, *val = input().split(' ')
    if query == '0':
        dict[val[0]] = int(val[1])
    elif query == '1':
        print(dict.get(val[0], 0))
    else:
        dict.pop(val[0])