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: Runtime Error

Solution code:
#coding:utf-8
n = int(input())

def converter(string):
    ch_list = ["A", "C", "G", "T"]
    new_string = ""
    for ch in string:
        for i in range(4):
            if ch == ch_list[i]:
                new_string += str(i+1)
    return int(new_string)

    
def sosu(num):
    while True:
        i = 2
        while i <= num ** (1/2) :
            if num % i != 0:
                i += 1
            else:
                num += 1
                i = 2
        break
    return num


def h1(key):
    return key % m

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

def hf(key, i):
    return (h1(key)+i*h2(key)) % m

def insert(T, key):
    i = 0
    while True:
        j = hf(key, i)
        if T[j] == None:
            T[j] = key
            break
        else:
            i += 1

def search(T, key):
    i = 0
    while True:
        j = hf(key, i)
        if T[j] == key:
            return "yes"
        elif T[j] == None or i >= m:
            return "no"
        else:
            i += 1


#m = int(n*1.2)
m = sosu(m)
T = [None for num in range(m)]

cnt = 0
for i in range(n):
    order, string = input().split()
    if order == "insert":
        key = converter(string)
        insert(T,key)
    if order == "find":
        key = converter(string)
        print(search(T, key))

Submission status: Runtime Error

Solution code:
class BTree:
    def __init__(self):
        self.value = None
        self.left = None
        self.right = None

    def insert(self, s):
        if self.value is None:
            self.value = s
        else:
            if self.value < s:
                if self.right is None:
                    self.right = BTree().insert(s)
                else:
                    self.right = self.right.insert(s)
            elif s < self.value:
                if self.left is None:
                    self.left = BTree().insert(s)
                else:
                    self.left = self.left.insert(s)
        return self

    def find(self, s):
        if self.value == s:
            return True
        elif self.value < s:
            if self.right is None:
                return False
            else:
                return self.right.find(s)
        else:
            if self.left is None:
                return False
            else:
                return self.left.find(s)


n = int(input())
tree = BTree()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        tree = tree.insert(command[1])
    elif command[0] == "find":
        if tree.find(command[1]):
            print("yes")
        else:
            print("no")

Submission status: Runtime Error

Solution code:
class BTree:
    def __init__(self):
        self.value = "ZZZ"
        self.left = None
        self.right = None

    def insert(self, s):
        if self.value is None:
            self.value = s
        else:
            if self.value < s:
                if self.right is None:
                    self.right = BTree().insert(s)
                else:
                    self.right = self.right.insert(s)
            elif s < self.value:
                if self.left is None:
                    self.left = BTree().insert(s)
                else:
                    self.left = self.left.insert(s)
        return self

    def find(self, s):
        if self.value == s:
            return True
        elif self.value < s:
            if self.right is None:
                return False
            else:
                return self.right.find(s)
        else:
            if self.left is None:
                return False
            else:
                return self.left.find(s)


n = int(input())
tree = BTree()
for _ in range(n):
    command = input().split()
    if command[0] == "insert":
        tree = tree.insert(command[1])
    elif command[0] == "find":
        if tree.find(command[1]):
            print("yes")
        else:
            print("no")

Submission status: Runtime Error

Solution code:
D = []

def append(value):
    global D

    hashvalue = ""
    for letter in value:
        hashvalue += str(ord(letter))

    D.append(int(hashvalue))

def find(value):
    hashvalue = ""
    for letter in value:
        hashvalue += str(ord(letter))

    hashvalue = int(hashvalue)

    left = 0
    right = len(D) - 1

    while True:
        mid = (left + right) // 2

        if D[mid] == hashvalue:
            print("yes")
            return
        elif D[mid] < hashvalue:
            left = mid + 1
        else:
            right = mid - 1

        if left > right:
            print("no")
            return


def main():
    global D

    N = int(input())
    finds = []

    for _ in range(N):
        command, value = [i for i in input().split()]

        if command == "insert":
            append(value)
            D.sort()
        else:
            find(value)

main()

Submission status: Runtime Error

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(1000000)]
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: Runtime Error

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

Submission status: WA: Presentation Error

Solution code:
def insert(S, string):
    S.append(string)

def find(S, string):
    cnt = 0
    for i in range(len(S)):
        cnt = cnt + 1
        if S[i] == string:
            print 'yes\n'
            break
        elif cnt == len(S):
            print 'no\n'

n = input()

S = []

for i in range(n):
    tmp1, tmp2  = map(str,raw_input().split())
    if tmp1 == 'insert':
        insert(S, tmp2)
    elif tmp1 == 'find':
        find(S, tmp2)
    else:
        print 'error!'

Submission status: WA: Presentation Error

Solution code:
n = int(input())
dic = set()

for i in range(n):
    o = input().split()
    if o[0] == 'insert':
        dic.add(o[1])
    elif o[1] in dic:
        print('yes\n')
    else:
        print('no\n')

Submission status: WA: Presentation Error

Solution code:
class Dictionary_class:
    def __init__(self):
        self.dic = set()

    def insert(self, str):
        self.dic.add(str)

    def find(self, str):
        if str in self.dic:
            return True
        else:
            return False

n = int(input())
answer = ""
dic = Dictionary_class()
for i in range(n):
    instruction = input().split()
    if instruction[0] == "insert":
        dic.insert(instruction[1])
    elif instruction[0] == "find":
        if dic.find(instruction[1]):
            answer += "yes\n"
        else:
            answer += "no\n"
print(answer)