problemscpp
A collection of my answers to algorithm problems in c++.
Public 成员函数 | Private 属性 | 所有成员列表
leetcode::encrypt_and_decrypt_strings::Encrypter类 参考

#include <leetcode.h>

Public 成员函数

 Encrypter (vector< char > &keys, vector< string > &values, vector< string > &dictionary)
 用 keys、values 和 dictionary 初始化 Encrypter 类。 更多...
 
int decrypt (const string &word2)
 统计可以由 word2 解密得到且出现在 dictionary 中的字符串数目 更多...
 
string encrypt (const string &word1) const
 按上述加密过程完成对 word1 的加密 更多...
 

Private 属性

unordered_map< string, int > count
 
array< string, 26 > mp
 

详细描述

在文件 leetcode.h2067 行定义.

构造及析构函数说明

◆ Encrypter()

leetcode::encrypt_and_decrypt_strings::Encrypter::Encrypter ( vector< char > &  keys,
vector< string > &  values,
vector< string > &  dictionary 
)

用 keys、values 和 dictionary 初始化 Encrypter 类。

在文件 leetcode.cpp5625 行定义.

5625 {
5626 for(int i = 0; i < keys.size(); ++i) {
5627 mp[keys[i] - 'a'] = values[i];
5628 }
5629 for(const auto &s: dictionary) {
5630 ++count[encrypt(s)];
5631 }
5632 }
string encrypt(const string &word1) const
按上述加密过程完成对 word1 的加密
Definition: leetcode.cpp:5634

引用了 count, encrypt() , 以及 mp.

成员函数说明

◆ decrypt()

int leetcode::encrypt_and_decrypt_strings::Encrypter::decrypt ( const string &  word2)

统计可以由 word2 解密得到且出现在 dictionary 中的字符串数目

返回
可以由 word2 解密得到且出现在 dictionary 中的字符串数目

在文件 leetcode.cpp5646 行定义.

5646 {
5647 if(count.contains(word2)) {
5648 count[word2] += 0;
5649 return count[word2];
5650 }
5651 // 防止把不在 cnt 中的字符串加进去
5652 return 0;
5653 }

引用了 count.

◆ encrypt()

string leetcode::encrypt_and_decrypt_strings::Encrypter::encrypt ( const string &  word1) const

按上述加密过程完成对 word1 的加密

返回
加密后的字符串

在文件 leetcode.cpp5634 行定义.

5634 {
5635 string res;
5636 for(const char ch: word1) {
5637 const auto &s = mp[ch - 'a'];
5638 if(s.empty()) {
5639 return "";
5640 }
5641 res += s;
5642 }
5643 return res;
5644 }

引用了 mp.

被这些函数引用 Encrypter().

类成员变量说明

◆ count

unordered_map<string, int> leetcode::encrypt_and_decrypt_strings::Encrypter::count
private

在文件 leetcode.h2069 行定义.

被这些函数引用 Encrypter() , 以及 decrypt().

◆ mp

array<string, 26> leetcode::encrypt_and_decrypt_strings::Encrypter::mp
private

在文件 leetcode.h2068 行定义.

被这些函数引用 Encrypter() , 以及 encrypt().


该类的文档由以下文件生成: