Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4aab76c

Browse files
committed
Time: 472 ms (76.92%), Space: 113.3 MB (61.54%) - LeetHub
1 parent 26edde7 commit 4aab76c

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
class Encrypter {
2+
public:
3+
unordered_map<char,string>m;
4+
vector<string>v1;
5+
Encrypter(vector<char>& k, vector<string>& v, vector<string>& d) {
6+
7+
int i,n=v.size();
8+
for(i=0;i<n;i++)
9+
{
10+
m[k[i]]=v[i];
11+
}
12+
13+
for(i=0;i<d.size();i++)
14+
{
15+
v1.push_back(d[i]);
16+
}
17+
18+
}
19+
20+
string encrypt(string w) {
21+
22+
int i,n=w.size();
23+
string s;
24+
for(i=0;i<n;i++)
25+
{
26+
s+=m[w[i]];
27+
}
28+
return s;
29+
30+
}
31+
32+
int decrypt(string w) {
33+
34+
int i,n=w.size(),ans=0;
35+
36+
for(i=0;i<v1.size();i++)
37+
{
38+
string s="";
39+
for(int j=0;j<v1[i].size();j++)
40+
{
41+
s+=m[v1[i][j]];
42+
}
43+
44+
45+
ans+=s==w;
46+
47+
}
48+
49+
return ans;
50+
}
51+
};
52+
53+
/**
54+
* Your Encrypter object will be instantiated and called as such:
55+
* Encrypter* obj = new Encrypter(keys, values, dictionary);
56+
* string param_1 = obj->encrypt(word1);
57+
* int param_2 = obj->decrypt(word2);
58+
*/

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /