Problem:


Search III

Your task is to write a program of a simple dictionary which implements the following instructions:

insert str: insert a string str in to the dictionary

find str: if the distionary contains str, then print 'yes', otherwise print 'no'

Input

In the first line n, the number of instructions is given. In the following n lines, n instructions are given in the above mentioned format.

Output

Print yes or no for each find instruction in a line.

Constraints

A string consists of 'A', 'C', 'G', or 'T'

1 ≤ length of a string ≤ 12

 n ≤ 1000000 

Sample Input 1

5
insert A
insert T
insert C
find G
find A

Sample Output 1

no
yes

Sample Input 2

13
insert AAA
insert AAC
insert AGA
insert AGG
insert TTT
find AAA
find CCC
find CCC
insert CCC
find CCC
insert T
find TTT
find T

Sample Output 2

yes
no
no
yes
yes
yes

Notes

Template in C



Sample input:
5
insert A
insert T
insert C
find G
find A


Sample output:
no
yes

Submission status: Accepted

Solution code:


def main():
    n = int(input())
    d = set()
    for _ in range(n):
        op, s = input().split()
        if op == 'insert':
            d.add(s)
        else:
            if s in d:
                print('yes')
            else:
                print('no')

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
data = set()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        data.add(command[1])
    elif command[0] == "find":
        if command[1] in data:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
def main():
    n = int(stdinput())

    st = [None] * (4**12)

    for _ in range(n):
        cmd, value = stdinput().split()
        if cmd == 'insert':
            st[get_hash(value)] = 1
        elif cmd == 'find':
            if st[get_hash(value)] == 1:
                print('yes')
            else:
                print('no')

CODES = {'A' : 1, 'C' : 2, 'G' : 3, 'T' : 4}
def get_hash(s):
    base = 1
    h = 0
    for c in s:
        code = CODES[c]
        h += code * base
        base *= 4
    return h

def stdinput():
    from sys import stdin
    return stdin.readline().strip()

if __name__ == '__main__':
    main()
    # import cProfile
    # cProfile.run('main()')

Submission status: Accepted

Solution code:
n = int(input())

s = set()

for _ in range(n):
    instruction, word = input().split()
    if instruction == 'insert':
        s.add(word)
    else:
        if word in s:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
if __name__ == "__main__":
    
    n = int(input())
    ops = []
    words = []
    for _ in range(n):
        op, word = input().split()
        ops.append(op)
        words.append(word)
    
    db = set()
    for op, word in zip(ops, words):
        if op=='insert':
            db.add(word)
        else:
            if word in db:
                print("yes")
            else:
                print("no")

Submission status: Accepted

Solution code:
from sys import stdin

n = int(stdin.readline())

d = {}
for i in range(n):
    cmd = stdin.readline()
    if cmd.startswith('insert'):
        s = cmd[7:-1]
        d[s] = True
    elif cmd.startswith('find'):
        s = cmd[5:-1]
        print('yes' if s in d else 'no')

Submission status: Accepted

Solution code:
# AOJ ALDS1_4_C Dictionary
# Python3 2018.7.3 bal4u

dic = {}
n = int(input())
for i in range(n):
	id, s = input().split()
	if id == "insert": dic[s] = 1
	else: print("yes" if s in dic else "no")

Submission status: Accepted

Solution code:
# AOJ ALDS1_4_C Dictionary
# Python3 2018.7.3 bal4u

import sys
from sys import stdin
input = stdin.readline

dic = {}
n = int(input())
for i in range(n):
	s = input()
	if s[0] == 'i': dic[s[7:]] = 1
	else: print("yes" if s[5:] in dic else "no")

Submission status: Accepted

Solution code:
n = input()
S = set()
for i in xrange(n):
    inst, s = raw_input().split()
    if inst == "insert":
        S.add(s)
    else:
        if s in S:
            print "yes"
        else:
            print "no"

Submission status: Accepted

Solution code:
def f():
    return raw_input()
def f2():
    return raw_input().split()

dic = {}
n = int(f())
for i in range(n):
    c1, c2 = f2()
    if c1 == 'insert':
        dic[c2] = 0
    elif c1 == 'find':
        if dic.has_key(c2):
            print 'yes'
        else:
            print 'no'

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin
n = int(stdin.readline())
readline = stdin.readline
d = dict()
while n:
    n -= 1
    cmd, c = readline().split()
    if cmd.startswith('i'):
        d[c] = True
    elif d.get(c):
        print('yes')
    else:
        print('no')

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
#start = time.clock()
#i = 0
#check = 'insert'
n=input()
a=set()
for x in xrange(n):
    (i,f)=map(str, raw_input().split())
    if i=='insert':
        a.add(f)
    else:
        if f in a:
            print 'yes'
        else:
            print 'no'

Submission status: Accepted

Solution code:
dict = {"A":1,"C":2,"G":3,"T":4}
def a2n(a):
	ans = 0
	for i in range(len(a)):
		ans += dict[a[i]]*4**i
	return ans
	
n = int(raw_input())
ls = [0 for i in range(6710886)]
for i in range(n):
    inp = raw_input()
    if inp[0] == "i":
        ls[a2n(inp[7:])] = 1
    else:
        print "yes" if ls[a2n(inp[5:])] else "no"

Submission status: Accepted

Solution code:
dict = {"A":1,"C":2,"G":3,"T":4}
def a2n(a):
	ans = 0
	for i in range(len(a)):
		ans += dict[a[i]]*4**i
	return ans
	
n = int(raw_input())
ls = [0 for i in range(3000000)]
for i in range(n):
    inp = raw_input()
    if inp[0] == "i":
        ls[a2n(inp[7:])] = 1
    else:
        print "yes" if ls[a2n(inp[5:])] else "no"

Submission status: Accepted

Solution code:
n = int(raw_input())
ls = {}
for i in range(n):
    inp = raw_input()
    if inp[0] == "i":
        ls[inp[7:]] = 1
    else:
        try:
        	if ls[inp[5:]] == 1: print "yes"
        except:
        	print "no"

Submission status: Accepted

Solution code:
n = int(raw_input())
ls = {}
for i in range(n):
    inp = raw_input()
    if inp[0] == "i":
        ls[inp[7:]] = 1
    else:
        try:
        	if ls[inp[5:]]: print "yes"
        except:
        	print "no"

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    cmd = input()
    if cmd[0] == 'i':
        d[cmd[7:]] = 0
    else:
        print('yes' if cmd[5:] in d else 'no')

Submission status: Accepted

Solution code:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

n = I()
M = 1046527
NIL = -1
H = [None] * M
com = []
ch = []

for i in range(n):
    com_, ch_ = input().split()
    com.append(com_)
    ch.append(ch_)


table = str.maketrans({
'A':'1',
'C':'2',
'G':'3',
'T':'4',
})


def getChar(ch):
    return int(ch.translate(table))

def h1(key):
    return key % M
def h2(key):
    return 1 + (key % (M - 1))

def insert(ch):
    key = getChar(ch)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] is None:
            H[h] = ch
            break
        else:
            i += 1

def find(ch):
    key = getChar(ch)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == ch:
            return 1
        elif H[h] is None:
            return 0
        else:
            i += 1


for i in range(n):
    if com[i][0] == 'i':
        insert(ch[i])
    else:
        if find(ch[i]):
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
M = 1046527
POW = [pow(4, i) for i in range(13)]


def insert(dic, string):
    # i = 0
    # while dic[(hash1(string) + i*hash2(string)) % M]:
    #     i += 1
    # dic[(hash1(string) + i*hash2(string)) % M] = string
    dic[get_key(string)] = string


def find(dic, string):
    # i = 0
    # while dic[(hash1(string) + i*hash2(string)) % M] and dic[(hash1(string) + i*hash2(string)) % M] != string:
    #     i += 1
    # return True if dic[(hash1(string) + i*hash2(string)) % M] == string else False
    # print(dic[get_key(string)], string)
    return True if dic[get_key(string)] == string else False


def get_num(char):
    if char == "A":
        return 1
    elif char == "C":
        return 2
    elif char == "G":
        return 3
    else:
        return 4


def get_key(string):
    num = 0
    for i in range(len(string)):
        num += POW[i] * get_num(string[i])
    return num


def main():
    n = int(input())
    dic = [None] * POW[12]
    # print(dic)
    for i in range(n):
        order, string = input().split()
        if order == "insert":
            insert(dic, string)
        else:
            if find(dic, string):
                print('yes')
            else:
                print('no')


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
dic = {}
for _ in range(N):
    command, string = input().split()
    if command == "insert":
        dic[string] = 1
    else:
        if string in dic:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
from sys import stdin
n = int(input())
dict = {}
for i in range(n):
    line = stdin.readline()
    if line[0:6] == 'insert':
        dict[line[7:]] = 1
    else:
        if line[5:] in dict:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
n = int(input())
dictionary = {}
for _ in range(n):
    command, word = input().split()
    if command == 'insert':
        dictionary[word] = word
    else:
        if dictionary.get(word) != None:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
n = int(input())
D = set()
for _ in range(n):
    q, s = map(str, input().split())
    if q == 'insert':
        D.add(s)
    elif q == 'find':
        if s in D:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
from sys import stdin
import sys
input = stdin.readline

dic = {}
n = int(input())
for i in range(n):
    s = input()
    if s[0] == 'i':
        dic[s[7:]] = 1
    else:
        print("yes" if s[5:] in dic else "no")

Submission status: Accepted

Solution code:
s = {0}
for i in [*open(0)][1:]:
    a, b = i.split()
    if a == "insert":
        s |= {b}
    else:
        print("yes" if b in s else "no")

Submission status: Accepted

Solution code:
n = int(input())
d = {}

while n > 0:
    n -= 1
    c,m = input().split()

    if c == "insert":
        d[m] = 0

    else:
        if m in d:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
n = int(input())
dic = set()
for i in range(n):
    order, Str = input().split()
    if order=='insert':
        dic.add(Str)
    if order=='find':
        if Str in dic:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
import sys
d = {}

n = int(input())
for i in sys.stdin:
    q, c = i.split()
    if q == 'find':
        if c in d:
            print('yes')
        else:
            print('no')

    else:
        d[c] = True

Submission status: Accepted

Solution code:
n = int(input())
d = set() 
result = []
for _ in range(n):
    command, s = input().split()
    if command == 'insert':
        d.add(s)
    elif command == 'find':
        if s in d:
            result.append('yes')
        else:
            result.append('no')

for r in result:
    print(r)

Submission status: Accepted

Solution code:
num=int(input())
command=[input().split() for i in range(num)]
dic={}

for i in command:
    if i[0]=="insert":
        dic[i[1]]=1
    if i[0]=="find":
        if i[1] in dic:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
import sys

M = 1044697
H = [None] * M

table = str.maketrans({"A":"1","C":"2","G":"3","T":"4"})


def getChar(ch):
    if ch == "A":
        return 1
    elif ch == "C":
        return 2
    elif ch == "G":
        return 3
    elif ch == "T":
        return 4
    else:
        return 0

def getKey(string):
    sum = 0
    p = 1
    for i in range(len(string)):
        sum += p*(getChar(string[i]))
        p *= 5
    return sum

#print(getKey(string))

def h1(key):
    return key % M

def h2(key):
    return 1 + (key % (M-1))

# 関数の中のwhile文はreturnで抜け出せる
def find(string):
    i = 0
    key = getKey(string)
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == string:
            return 1
        elif H[h] is None:
            return 0
        else:
            i += 1

def insert(string):
    i = 0
    key = getKey(string)
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] is None:
            H[h] = string
            break
        else:
            i += 1


input = sys.stdin.readline
n = int(input())

for _ in range(n):
    com,string = input().split()
    if com == "insert":
        insert(string)
    elif com == "find":
        if find(string):
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
#define hash
class my_dict():
    def __init__(self, size=1000):
        self.my_list = [[] for i in range(size)]
        self.dict_size = size
    #quaternary A=0 C=1 G=2 T=3
    def acgt_hash(self, input_str):
        output = 0
        for i in input_str:
            if i == 'A':
                output+=1
            elif i == 'C':
                output+=2
            elif i == 'G':
                output+=3
            elif i == 'T':
                output+=4
            output *=5
        return output%self.dict_size
    def insert(self, key):
        hash_val = self.acgt_hash(key)
        if self.my_list[hash_val] == None:
            self.my_list[hash_val]  = [key]
        else:
            for k in self.my_list[hash_val]:
                if k == key:
                    break
            else: self.my_list[hash_val].append(key)
    def find(self, key):
        hash_val = self.acgt_hash(key)
        if self.my_list[hash_val] == None:
            print('no')
        else:
            for k in self.my_list[hash_val]:
                if k == key:
                    print('yes')
                    break
            else: print('no')

#get N
n = int(input())
#create dic
dic1 = my_dict(100000)
#get inputs in N times
for i in range(n):
    #get instructtion and key
    inst, key = input().split(' ')
    #do instructions
    if inst == 'insert':
        dic1.insert(key)
    else:
        dic1.find(key)

Submission status: Accepted

Solution code:
class HashTable:

    @staticmethod
    def h1(key):
        return key % 1046527

    @staticmethod
    def h2(key):
        return 1 + (key % (1046527 - 1))
    
    def __init__(self, size):
        self.size = size
        self.values = [None for _ in range(size)]
        self.tables = str.maketrans({
            'A':'1', 'C':'2', 'G':'3', 'T':'4',
        })

    def translate_key(self, value):
        return int(value.translate(self.tables))

    def find(self, value):
        count = 0
        key = self.translate_key(value)

        while True:
            h = (HashTable.h1(key) + count * HashTable.h2(key)) % 1046527
            if self.values[h] == value:
                return True
            elif self.values[h] is None:
                return False
            count += 1
        return False

    def insert(self, value):
        count = 0
        key = self.translate_key(value)
        
        while True:
            h = (HashTable.h1(key) + count * HashTable.h2(key)) % 1046527
            if self.values[h] is None:
                self.values[h] = value
                break
            count += 1


num = int(input())

dictionary = HashTable(1046527)
for _ in range(num):
    command, value = input().split()
    if command == "insert":
        dictionary.insert(value)
    elif command == "find":
        is_find = dictionary.find(value)
        print("yes" if is_find else "no")

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    a, b = input().split()
    if a == "insert":
        d[b] = True
    elif a == "find":
        print("yes" if b in d.keys() else "no")

Submission status: Accepted

Solution code:
class Dictionary:
    def __init__(self):
        self.data = {}
        
    def insert(self, value:str):
        self.data[value] = True

    def find(self, value:str):
        if value in self.data:
            return 'yes'
        return 'no'

if __name__ == '__main__':
    my_dict = Dictionary()
    n = int(input())
    for _ in range(n):
        comm = list(map(str, input().rstrip().split()))
        if comm[0] == 'insert':
            my_dict.insert(comm[1])
        elif comm[0] == 'find':
            print(my_dict.find(comm[1]))

Submission status: Accepted

Solution code:
my_set = set()

n = int(input())
for _ in range(n):
    command, dna = input().split()
    if command == 'insert':
        my_set.add(dna)
    elif dna in my_set:
        print('yes')
    else:
        print('no')

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    d = set()

    for _ in range(N):
        inst, str = sl()
        if inst == 'insert':
            d.add(str)
        elif inst == 'find' and str in d:
            print('yes')
        else:
            print('no')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
d = {}
for i in range(n):
    a, b = input().split()
    if a == "insert":
        d[b] = 1
    else:
        print("yes" if b in d else "no")

Submission status: Accepted

Solution code:
s = set()

for _ in range(int(input())):
    cmd, v = input().split()
    if cmd == 'insert':
        s.add(v)
    else:
        print('yes' if v in s else 'no')

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline


N = int(input())
d = dict()

for _ in range(N):
    op, key = input().strip().split()
    if op == "insert":
        d[key] = True
    elif op == "find" and key in d.keys():
        print("yes")
    else:
        print("no")

Submission status: Accepted

Solution code:
n = int(input())
dic_A = set()
dic_C = set()
dic_G = set()
dic_T = set()
for i in range(n) :
    p, string = input().split()
    if p == 'insert' :
        if string[0] == 'A' :
            dic_A.add(string)
        elif string[0] == 'C' :
            dic_C.add(string)
        elif string[0] == 'G' :
            dic_G.add(string)
        else :
            dic_T.add(string)
    else :
        if string[0] == 'A' :
            if string in dic_A :
                print('yes')
            else :
                print('no')
        elif string[0] == 'C' :
            if string in dic_C :
                print('yes')
            else :
                print('no')
        elif string[0] == 'G' :
            if string in dic_G :
                print('yes')
            else :
                print('no')
        else :
            if string in dic_T :
                print('yes')
            else :
                print('no')

Submission status: Accepted

Solution code:
d = {}
n = int(input())
for _ in range(n):
    a, b = input().split()
    if a == 'insert':
        d[b] = b
    elif a == 'find':
        print('yes' if b in d.keys() else 'no')

Submission status: Accepted

Solution code:
#他の方の解答を参考にさせていただきました。
dic = {}
n = int(input())
for i in range(n):
	s = input()
	if s[0] == 'i': dic[s[7:]] = "a"
	else: print("yes" if s[5:] in dic else "no")

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	dic
# CreatedDate:  2020-06-30 15:07:10 +0900
# LastModified: 2020-06-30 15:09:49 +0900
#


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


def main():
    n = int(input())
    dic = {}
    for _ in range(n):
        command, s = input().split()
        if command == 'insert':
            dic[s] = 1
#            print(dic)
        else:
            print("yes" if s in dic.keys() else "no")



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    from collections import deque
    n = int(input())
    dic = {}

    for i in range(n):
        x = input().split()
        if x[0] == "insert":
            dic[x[1]] = 1
        if x[0] == "find":
            if x[1] in dic:
                print('yes')
            else:
                print('no')

Submission status: Accepted

Solution code:
from sys import stdin

n = int(input())
set_ = set()

for _ in range(n):
    cmd, s = stdin.readline().split()

    if cmd == "insert":
        set_.add(s)
    if cmd == "find":
        ans = ["no", "yes"][s in set_]
        print(ans)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    operation = [input().split() for _ in range(n)]
    dictionary = {}
    
    for command, char in operation:
        if command == "insert":
            dictionary[char] = True
        elif command == "find":
            try:
                if dictionary[char]:
                    print("yes")
            except KeyError:
                print("no")
    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
dict = {}

def insert(word):
    global dict

    dict[word] = 0

def find(word):
    global dict
    if word in dict:
        print('yes')
    else:
        print('no')

def main():
    N = int(input())
    order = [list(input().split()) for _ in range(N)]

    for i in range(N):
        if order[i][0] == 'insert':
            insert(order[i][1])
        elif order[i][0] == 'find':
            find(order[i][1])

main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

if __name__ == '__main__':
  n=int(input())
  D=[0]*n
  A=[]

  def h1(x):
    return x%n

  def h2(x):
    return 1+x%(n-1)

  def h(x,i):
    return h1(x)+i*h2(x)

  def insert(x):
    i=0
    k=0
    while True:
      k=h(x,i)%n
      if D[k]==0:
        D[k]=x
        return k
      elif D[k]==x:
        return k
      i+=1

  def find(x):
    i=0
    k=0
    while i<n:
      k=h(x,i)%n
      if D[k]==x:
        return True
      elif D[k]==0:
        return False
      i+=1
    return False


  def getKey(X):
    res=''
    for x in X:
      if x=='A':
        res+='1'
      elif x=='C':
        res+='2'
      elif x=='G':
        res+='3'
      elif x=='T':
        res+='4'
    return int(res)

  for _ in range(n):
    c,x=input().strip("\n").split()
    #x=x.replace('A','1').replace('C','2').replace('G','3').replace('T','4')
    #x=int(x)
    x=getKey(x)
    if c=='insert':
      insert(x)
    else:
      A.append(find(x))
  for ans in A:
    print('yes' if ans else 'no')

Submission status: Accepted

Solution code:
N = int(input())
str_dict= {}

for i in range(N):
    a = input().split()
    if a[0] == "insert":
        str_dict[a[1]] = i
    else:
        if a[1] in str_dict.keys():
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin

Dic = {}
n = int(stdin.readline().rstrip())
for i in range(n):
  line = stdin.readline().rstrip()
  if line[0] == 'i':
    Dic[line[7:]] = 0
  else:
    print('yes' if line[5:] in Dic else 'no')

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline())

dic = {}
for i in range(n):
    s = sys.stdin.readline()
    if s[0] == 'i':
        dic[s[7:]] = 1
    else:
        if s[5:] in dic:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
dic = set()
n = int(input())
for i in range(n):
	s = input()
	if s[0] == 'i': 
	    dic.add(s[7:])
	    
	else: print("yes" if s[5:] in dic else "no")

Submission status: Accepted

Solution code:
n = int(input())
length = 1000018
sosu = 500009
ht = [-1] * length


def convert(moji):
    l_moji = len(moji)
    num = 0
    for j in range(l_moji):
        keta = 10 ** (l_moji - j - 1)
        if moji[j] == 'A':
            num += keta * 1
        if moji[j] == 'C':
            num += keta * 2
        if moji[j] == 'G':
            num += keta * 3
        if moji[j] == 'T':
            num += keta * 4
    return num


def hash_in(nk, num, m):
    if m == 0:
        return False
    hash_num = nk + (num % m)
    if hash_num > length:
        hash_num -= length
    if ht[hash_num] == -1:
        ht[hash_num] = num
    elif ht[hash_num] != num:
        hash_in(hash_num, num, m-1)
    return


def find(nk, num, m):
    if m == 0:
        return 'no'
    hash_num = nk + (num % m)
    if hash_num > length:
        hash_num -= length
    if ht[hash_num] == -1:
        return 'no'
    elif ht[hash_num] != num:
        return find(hash_num, num, m-1)
    elif ht[hash_num] == num:
        return 'yes'


def main():
    output = list()
    for i in range(n):
        command = list(input().split())
        num = convert(command[1])
        if command[0] == 'insert':
            if hash_in(0, num, sosu) is not None:
                print('an error is occured')
                break
        if command[0] == 'find':
            output.append(find(0, num, sosu))

    for j in output:
        print(j)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
s = set()
for i in range(n):
    a,b = input().strip().split()
    if a == 'insert':
        s.add(b)
    if a == 'find':
        if b in s:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
n = int(input())
s = set()
for _ in range(n):
    i = input()
    if i[0] == 'i':
        s |= {i[7:]}
    else:
        if i[5:] in s:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    before = set()
    for _ in range(N):
        s,t = input().split()
        if s == 'insert':
            before.add(t)
        else:
            if t in before:
                print('yes')
            else:
                print('no')
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n= int(input())
s= set()
for _ in range(n):
    a,b= input().split()
    if a=="insert":
        s.add(b)
    elif b in s:
        print("yes")
    else:
        print("no")

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())

dict = {}

for _ in range(n):
    op, key = input().split()

    if op == "insert":
        dict[key] = "insert"
        continue

    if op == "find":
        print("yes") if key in dict.keys() else print("no")

Submission status: Accepted

Solution code:
import sys
input()
d = {}
for s in sys.stdin:
    if s[0]=='i':
        d[s[7:]] = 1
    else:
        if s[5:] in d:
            print('yes')
        else:
            print('no')

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    s = set()
    for _ in range(N):
        a, b = input().split()
        if a == "insert":
            s.add(b)
        else:
            if b in s:
                print("yes")
            else:
                print("no")


resolve()

Submission status: Accepted

Solution code:
from typing import Dict


def main():
    n: int = int(input())
    d: Dict[str, bool] = {}

    for _ in range(n):
        command = input().split()
        if command[0] == "insert":
            d[f"{command[1]}"] = True
        else:
            if command[1] in d:
                print("yes")
            else:
                print("no")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n = int(input())

A = {}

for i in range(n):
    a, b = input().split()
    if a[0] == "i":
        A[b] = 1
    elif a[0] == "f":
        if b in A:
            print("yes")
        else:
            print("no")

Submission status: Accepted

Solution code:
class Dic:
    def __init__(self):
        self.end = False
        self.a = self.c = self.g = self.t = 0
    def insert(self, s):
        node = self
        index = 0
        while index < len(s):
            c = s[index]
            child = 0
            if c == 'A':
                if not node.a:
                    node.a = Dic()
                child = node.a
            elif c == 'C':
                if not node.c:
                    node.c = Dic()
                child = node.c
            elif c == 'G':
                if not node.g:
                    node.g = Dic()
                child = node.g
            elif c == 'T':
                if not node.t:
                    node.t = Dic()
                child = node.t
            else:
                return
            node = child
            index += 1
        node.end = True
    def find(self, s):
        node = self
        index = 0
        while index < len(s):
            c = s[index]
            child = 0
            if c == 'A':
                child = node.a
            elif c == 'C':
                child = node.c
            elif c == 'G':
                child = node.g
            elif c == 'T':
                child = node.t
            if child == 0:
                return False
            node = child
            index += 1
        return node.end

dic = Dic()

n = int(input())
for _ in range(n):
    cmd = list(input().split())
    if cmd[0] == 'insert':
        dic.insert(cmd[1])
    elif cmd[0] == 'find':
        print('yes' if dic.find(cmd[1]) else 'no')

Submission status: Accepted

Solution code:
# ALDS1_4_C.py
N = int(input())
dict = {}
for i in range(N):
    query, s = input().split()
    if query == "insert":
        dict[s] = True
    else:
        print('yes' if s in dict else 'no')

Submission status: Accepted

Solution code:
class diction:
    def __init__(self):
        self.D = {}
    def insert(self,string):
        self.D[string] = True
    def find(self,string):
        try:
            if self.D[string]:print('yes')
        except KeyError:
            print('no')
            
D = diction()
for _ in range(int(input())):
    command,string = input().split()
    if command == 'insert':
        D.insert(string)
    elif command == 'find':
        D.find(string)