-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem_2325_decodeMessage.cc
More file actions
52 lines (48 loc) · 993 Bytes
/
Copy pathProblem_2325_decodeMessage.cc
File metadata and controls
52 lines (48 loc) · 993 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <cctype>
#include <iostream>
#include <string>
#include <unordered_map>
#include "UnitTest.h"
using namespace std;
class Solution
{
public:
string decodeMessage(string key, string message)
{
char c = 'a';
std::unordered_map<char, char> map;
for (auto & i: key)
{
if (i != ' ' && map.count(i) == 0)
{
map[i] = c++;
}
}
for (auto & i:message)
{
if (map.count(i))
{
i = map[i];
}
}
return message;
};
};
void testDecodeMessage()
{
Solution s;
string k1 = "the quick brown fox jumps over the lazy dog";
string m1 = "vkbs bs t suepuv";
string o1 = "this is a secret";
string k2 = "eljuxhpwnyrdgtqkviszcfmabo";
string m2 = "zwx hnfx lqantp mnoeius ycgk vcnjrdb";
string o2 = "the five boxing wizards jump quickly";
EXPECT_TRUE(o1 == s.decodeMessage(k1, m1));
EXPECT_TRUE(o2 == s.decodeMessage(k2, m2));
EXPECT_SUMMARY;
}
int main()
{
testDecodeMessage();
return 0;
}