当前位置:网站首页>Leetcode-6108: decrypt messages
Leetcode-6108: decrypt messages
2022-07-05 06:09:00 【Chrysanthemum headed bat】
leetcode-6108: Decrypt the message
subject
Topic linking
Here is the string key
and message
, Represent an encryption key and an encrypted message respectively . Decrypt message
The steps are as follows :
Use key
in 26 The order of the first occurrence of English lowercase letters is used to replace the letters in the table The order .
Align the replacement table with the common English alphabet , Form a comparison table .
According to the comparison table Replace message
Every letter in .
Space ' '
remain unchanged .
for example ,key = "happy boy"
( The actual encryption key will contain every letter in the alphabet At least once ), Accordingly , You can get some comparison tables ('h' -> 'a'
、'a' -> 'b
’、'p' -> 'c'
、'y' -> 'd'
、'b' -> 'e'
、'o' -> 'f'
).
Returns the decrypted message .
Example 1:
Input :key = "the quick brown fox jumps over the lazy dog", message = "vkbs bs t suepuv"
Output :"this is a secret"
explain : The comparison table is shown in the above figure .
extract "the quick brown fox jumps over the lazy dog" The first occurrence of each letter in can get a replacement table .
Example 2:
Input :key = "eljuxhpwnyrdgtqkviszcfmabo", message = "zwx hnfx lqantp mnoeius ycgk vcnjrdb"
Output :"the five boxing wizards jump quickly"
explain : The comparison table is shown in the above figure .
extract "eljuxhpwnyrdgtqkviszcfmabo" The first occurrence of each letter in can get a replacement table .
Problem solving
Method 1 : Hashtable
1. By hashing map, Record each letter in key The order in which they first appear , And assign corresponding letters .
2. Space directly skip , Replace letters
class Solution {
public:
string decodeMessage(string key, string message) {
unordered_map<char,char> map;
char c='a';
for(int i=0;i<key.size();i++){
if(key[i]==' ') continue;
if(!map.count(key[i])){
map[key[i]]=c;
c++;
}
}
for(int i=0;i<message.size();i++){
if(message[i]==' ') continue;
char c=message[i];
message[i]=map[c];
}
return message;
}
};
边栏推荐
- Common optimization methods
- [rust notes] 16 input and output (Part 1)
- 【Rust 笔记】16-输入与输出(下)
- [jailhouse article] performance measurements for hypervisors on embedded ARM processors
- leetcode-556:下一个更大元素 III
- Analysis of backdoor vulnerability in remote code execution penetration test / / phpstudy of national game title of national secondary vocational network security B module
- QT判断界面当前点击的按钮和当前鼠标坐标
- LeetCode 0107.二叉树的层序遍历II - 另一种方法
- 【Rust 笔记】13-迭代器(下)
- leetcode-6108:解密消息
猜你喜欢
Smart construction site "hydropower energy consumption online monitoring system"
从Dijkstra的图灵奖演讲论科技创业者特点
Appium automation test foundation - Summary of appium test environment construction
Solution to game 10 of the personal field
1.15 - 输入输出系统
Is it impossible for lamda to wake up?
Full Permutation Code (recursive writing)
Brief introduction to tcp/ip protocol stack
Open source storage is so popular, why do we insist on self-development?
Individual game 12
随机推荐
全排列的代码 (递归写法)
shared_ Repeated release heap object of PTR hidden danger
Overview of variable resistors - structure, operation and different applications
7. Processing the input of multidimensional features
1996. number of weak characters in the game
做 SQL 性能优化真是让人干瞪眼
Multi screen computer screenshots will cut off multiple screens, not only the current screen
从Dijkstra的图灵奖演讲论科技创业者特点
QQ电脑版取消转义符输入表情
F - Two Exam(AtCoder Beginner Contest 238)
1.13 - RISC/CISC
Codeforces Round #732 (Div. 2) D. AquaMoon and Chess
【Rust 笔记】14-集合(上)
QQ computer version cancels escape character input expression
Introduction to convolutional neural network
【Rust 笔记】14-集合(下)
智慧工地“水电能耗在线监测系统”
多屏电脑截屏会把多屏连着截下来,而不是只截当前屏
leetcode-6108:解密消息
Data visualization chart summary (II)