호그와트

행복한 은행 관리법

영웅*^%&$ 2022. 6. 15. 13:28
728x90

packagemydict

import(

"errors"

)

typeDictionarymap[string]string

var(

NotFound = errors.New("Not found")

errCantUpdate = errors.New("Can't update nonexistsing word")

errWordExists = errors.New("That word already exists")

)

func(d Dictionary)Search(word string)(string,error){

value, exits := d[word]

if exits {

return value,nil

}

return"", NotFound

}

func(d Dictionary)Add(word, def string)error{

_, err := d.Search(word)

if err == NotFound {

d[word]= def

}elseif err ==nil{

return errWordExists

}

returnnil

}

func(d Dictionary)Update(word, definition string)error{

_, err := d.Search(word)

switch err {

casenil:

d[word]= definition

case NotFound :

return errCantUpdate

}

returnnil

}

func(d Dictionary)Delete(word string){

delete(d, word)

}

728x90

'호그와트' 카테고리의 다른 글

드림핵 out of bound  (0) 2022.06.21
드림핵 csp bypass advanced 초 간단 풀이  (0) 2022.06.18
적정한 암호 생성하기  (0) 2022.06.13
드림핵 secret message 목을 딸 때가 왔다  (0) 2022.05.31
beauty 후후훗  (0) 2022.05.30