当前位置:网站首页>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;
}
};
边栏推荐
- [jailhouse article] jailhouse hypervisor
- Appium foundation - use the first demo of appium
- Sqlmap tutorial (II) practical skills I
- Navicat连接Oracle数据库报错ORA-28547或ORA-03135
- Codeforces Round #716 (Div. 2) D. Cut and Stick
- 【实战技能】如何做好技术培训?
- [rust notes] 13 iterator (Part 2)
- leetcode-6109:知道秘密的人数
- Typical use cases for knapsacks, queues, and stacks
- 1040 Longest Symmetric String
猜你喜欢
随机推荐
On the characteristics of technology entrepreneurs from Dijkstra's Turing Award speech
SPI details
[rust notes] 15 string and text (Part 1)
1041 Be Unique
Liunx starts redis
1041 Be Unique
开源存储这么香,为何我们还要坚持自研?
Transform optimization problems into decision-making problems
Introduction to convolutional neural network
【Rust 笔记】15-字符串与文本(下)
Spark中groupByKey() 和 reduceByKey() 和combineByKey()
Sqlmap tutorial (1)
[jailhouse article] jailhouse hypervisor
API related to TCP connection
1.14 - 流水线
一些工具的记录2022
leetcode-9:回文数
[rust notes] 17 concurrent (Part 2)
leetcode-6109:知道秘密的人数
[jailhouse article] look mum, no VM exits








