当前位置:网站首页>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;
}
};
边栏推荐
- 2022年贵州省职业院校技能大赛中职组网络安全赛项规程
- [practical skills] how to do a good job in technical training?
- leetcode-6108:解密消息
- Introduction to LVS [unfinished (semi-finished products)]
- The difference between CPU core and logical processor
- Collection: programming related websites and books
- Transform optimization problems into decision-making problems
- 做 SQL 性能优化真是让人干瞪眼
- leetcode-31:下一个排列
- 可变电阻器概述——结构、工作和不同应用
猜你喜欢
Smart construction site "hydropower energy consumption online monitoring system"
实时时钟 (RTC)
2017 USP Try-outs C. Coprimes
Introduction et expérience de wazuh open source host Security Solution
数据可视化图表总结(二)
SQLMAP使用教程(二)实战技巧一
Full Permutation Code (recursive writing)
R语言【数据集的导入导出】
从Dijkstra的图灵奖演讲论科技创业者特点
Dynamic planning solution ideas and summary (30000 words)
随机推荐
数据可视化图表总结(一)
Collection: programming related websites and books
【Rust 笔记】16-输入与输出(上)
Control unit
【Rust 笔记】13-迭代器(中)
Bit mask of bit operation
【Rust 笔记】14-集合(上)
leetcode-556:下一个更大元素 III
Educational Codeforces Round 116 (Rated for Div. 2) E. Arena
网络工程师考核的一些常见的问题:WLAN、BGP、交换机
Implement a fixed capacity stack
leetcode-6111:螺旋矩阵 IV
927. 三等分 模拟
Open source storage is so popular, why do we insist on self-development?
Introduction et expérience de wazuh open source host Security Solution
CF1637E Best Pair
1039 Course List for Student
6. Logistic model
Règlement sur la sécurité des réseaux dans les écoles professionnelles secondaires du concours de compétences des écoles professionnelles de la province de Guizhou en 2022
Introduction and experience of wazuh open source host security solution