classEncrypter:def__init__(self,keys:List[str],values:List[str],dictionary:List[str]):self.mp=dict(zip(keys,values))self.cnt=Counter(self.encrypt(v)forvindictionary)defencrypt(self,word1:str)->str:res=[]forcinword1:ifcnotinself.mp:return''res.append(self.mp[c])return''.join(res)defdecrypt(self,word2:str)->int:returnself.cnt[word2]# Your Encrypter object will be instantiated and called as such:# obj = Encrypter(keys, values, dictionary)# param_1 = obj.encrypt(word1)# param_2 = obj.decrypt(word2)
classEncrypter{privateMap<Character,String>mp=newHashMap<>();privateMap<String,Integer>cnt=newHashMap<>();publicEncrypter(char[]keys,String[]values,String[]dictionary){for(inti=0;i<keys.length;++i){mp.put(keys[i],values[i]);}for(Stringw:dictionary){w=encrypt(w);cnt.put(w,cnt.getOrDefault(w,0)+1);}}publicStringencrypt(Stringword1){StringBuildersb=newStringBuilder();for(charc:word1.toCharArray()){if(!mp.containsKey(c)){return"";}sb.append(mp.get(c));}returnsb.toString();}publicintdecrypt(Stringword2){returncnt.getOrDefault(word2,0);}}/** * Your Encrypter object will be instantiated and called as such: * Encrypter obj = new Encrypter(keys, values, dictionary); * String param_1 = obj.encrypt(word1); * int param_2 = obj.decrypt(word2); */
classEncrypter{public:unordered_map<string,int>cnt;unordered_map<char,string>mp;Encrypter(vector<char>&keys,vector<string>&values,vector<string>&dictionary){for(inti=0;i<keys.size();++i)mp[keys[i]]=values[i];for(autov:dictionary)cnt[encrypt(v)]++;}stringencrypt(stringword1){stringres="";for(charc:word1){if(!mp.count(c))return"";res+=mp[c];}returnres;}intdecrypt(stringword2){returncnt[word2];}};/** * Your Encrypter object will be instantiated and called as such: * Encrypter* obj = new Encrypter(keys, values, dictionary); * string param_1 = obj->encrypt(word1); * int param_2 = obj->decrypt(word2); */
typeEncrypterstruct{mpmap[byte]stringcntmap[string]int}funcConstructor(keys[]byte,values[]string,dictionary[]string)Encrypter{mp:=map[byte]string{}cnt:=map[string]int{}fori,k:=rangekeys{mp[k]=values[i]}e:=Encrypter{mp,cnt}for_,v:=rangedictionary{e.cnt[e.Encrypt(v)]++}returne}func(this*Encrypter)Encrypt(word1string)string{varansstrings.Builderfor_,c:=rangeword1{ifv,ok:=this.mp[byte(c)];ok{ans.WriteString(v)}else{return""}}returnans.String()}func(this*Encrypter)Decrypt(word2string)int{returnthis.cnt[word2]}/** * Your Encrypter object will be instantiated and called as such: * obj := Constructor(keys, values, dictionary); * param_1 := obj.Encrypt(word1); * param_2 := obj.Decrypt(word2); */