日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

破译。字符串匹配。HOJ1548 Crypt Kicker II。

發(fā)布時間:2025/3/14 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 破译。字符串匹配。HOJ1548 Crypt Kicker II。 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

用兩個map實現(xiàn)一一對應的判定。

Crypt Kicker II

Time limit:1sec.Submitted:122
Memory limit:32MAccepted:33
Source: Waterloo ACM Programming Contest Oct 4, 1998

A common but insecure method of encrypting text is to permute the letters of the alphabet. That is, in the text, each letter of the alphabet is consistently replaced by some other letter. So as to ensure that the encryption is reversible, no two letters are replaced by the same letter.

A common method of cryptanalysis is the known plaintext attack. In a known plaintext attack, the cryptanalist manages to have a known phrase or sentence encrypted by the enemy, and by observing the encrypted text then deduces the method of encoding.

Your task is to decrypt several encrypted lines of text, assuming that each line uses the same set of replacements, and that one of the lines of input is the encrypted form of the plaintext

the quick brown fox jumps over the lazy dog


Input

The input consists of several lines of input. Each line is encrypted as described above. Subsequent test cases are separated with a single blank line.


Output

Decrypt each line and print it to standard output. If there is more than one possible decryption, any one will do. If decryption is impossible, output a single line:

No solution.

The encrypted lines contain only lower case letters and spaces and do not exceed 80 characters in length. There are at most 100 input lines.

Separate output for subsequent cases with a single blank line.

Sample Input

vtz ud xnm xugm itr pyy jttk gmv xt otgm xt xnm puk ti xnm fprxq xnm ceuob lrtzv ita hegfd tsmr xnm ypwq ktj frtjrpgguvj otvxmdxd prm iev prmvx xnmq Sample Output now is the time for all good men to come to the aid of the party the quick brown fox jumps over the lazy dog programming contests are fun arent they


說明:
每組case給出幾行text。 某一行與"the quick brown fox jumps over the lazy dog" 字母一一對應。
找出來并將其余行破譯。
用兩個map分別建立 上述text與可能與之一一對應行之間的對應。
用來判斷是否有一個字母對應了兩個或者兩個不同的字母對應同一個的非法情況。

代碼如下:
#include<iostream>
#include
<stdio.h>
#include
<vector>
#include
<map>
using namespace std;

int main() {
int t = 0;
vector
<string> a;
string tmp;
string sta = "the quick brown fox jumps over the lazy dog";
while (getline(cin, tmp)) {
if (t)cout << endl;
t
++;
a.clear();
map
<char, char> m, opm;
bool flag2 = 1;
do {
a.push_back(tmp);
if (tmp.length() == sta.length() && flag2) {
m.clear();
opm.clear();
bool flag = 1;
for (int i = 0; i < tmp.length(); i++) {
if (sta[i] == ' ' && tmp[i] != ' ') {
flag
= 0;
break;
}
}
if (flag) {
bool flag3 = 1;
for (int i = 0; i < tmp.length(); i++) {
if (m.find(tmp[i]) != m.end()) {
if (m[tmp[i]] != sta[i]) {
flag3
= 0;
break;
}
}
else if (opm.find(sta[i]) != opm.end()) {
if (opm[sta[i]] != tmp[i]) {
flag3
= 0;
break;
}
}
else {
m[tmp[i]]
= sta[i];
opm[sta[i]]
= tmp[i];
}
}
if (flag3)
flag2
= 0;
}
}
}
while (getline(cin, tmp) && tmp != "");
if (flag2) {
cout
<< "No solution.\n";
continue;
}
for (int i = 0; i < a.size(); i++) {
for (int j = 0; j < a[i].length(); j++)
putchar(m[a[i][j]]);
cout
<< endl;
}
}
return 0;
}

轉載于:https://www.cnblogs.com/yangchenhao8/archive/2011/06/09/2076893.html

總結

以上是生活随笔為你收集整理的破译。字符串匹配。HOJ1548 Crypt Kicker II。的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。