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){cnt.merge(encrypt(w),1,Integer::sum);}}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); */
classEncrypter{privatemp:Map<string,string>=newMap();privatecnt:Map<string,number>=newMap();constructor(keys:string[],values:string[],dictionary:string[]){for(leti=0;i<keys.length;i++){this.mp.set(keys[i],values[i]);}for(constwofdictionary){constencrypted=this.encrypt(w);if(encrypted!==''){this.cnt.set(encrypted,(this.cnt.get(encrypted)||0)+1);}}}encrypt(word:string):string{letres='';for(constcofword){if(!this.mp.has(c)){return'';}res+=this.mp.get(c);}returnres;}decrypt(word:string):number{returnthis.cnt.get(word)||0;}}/** * Your Encrypter object will be instantiated and called as such: * const obj = new Encrypter(keys, values, dictionary); * const param_1 = obj.encrypt(word1); * const param_2 = obj.decrypt(word2); */