HDOJ HDU 1129 Do the Untwist
2017-09-12 20:41
232 查看
HDOJ 1129 Do the Untwist
题目
点此查看 HDOJ 1129 Do the Untwist分类
模拟题意
模拟解密字幕数字对照 “_” = 0, “a” = 1, “b” = 2,.., “z” = 26, 和 “.” = 27。
给出 k
计算公式 ciphercode[i] = (plaincode[ki mod n] - i) mod 28
解读一下公式
设 解密到 第i个字符(共 m 个字符)
意思是 明文的 第 (i *k) %m个字符 = (密文字母对应得数字 + i )% 28 再查表
例如 k = 5
Array | 0 | 1 | 2 |
---|---|---|---|
ciphertext | ‘c’ | ’s’ | ‘. |
ciphercode | 3 | 19 | 27 |
plaincode | 3 | 1 | 20 |
plaintext | ‘c’ | ‘a’ | ‘t’ |
第 (1 * 5) % 3 = 2 个字符 (s + 1)% 28 = 20 表中 20 是 ‘t’
第 (2 * 5) % 3 = 1 个字符 (. + 2)% 28 = 1 表中 1 是 ‘a’
解密完成
题解
模拟即可代码
#include <iostream> #include <cstring> #define maxn 100 #define maxt 28 using namespace std; int tab[maxt] = {'_','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','.'}; char plaincode[maxn]; int m,k; char ciphercode[maxn]; int findposition(char ch); int dectypto(); int main() { while(cin >> k && k) { memset(plaincode,0,sizeof(plaincode)); memset(ciphercode,0,sizeof(ciphercode)); cin >> ciphercode; m = strlen(ciphercode); dectypto(); cout << plaincode << endl; } return 0; } int dectypto() { for(int i = 0;i < m;i++) { plaincode [(i * k) % m] = tab[(findposition(ciphercode[i]) + i) % maxt]; } return 0; } int findposition(char ch) { for(int i = 0;i < maxt;i++) { if(tab[i] == ch) return i; } }
相关文章推荐
- 杭电1129 Do the Untwist
- HDU 1129 Do the Untwist
- hdoj 1129 Do the Untwist(数学公式+英文理解)
- hdu 1129 Do the Untwist
- 杭电ACM1129——Do the Untwist~~解密 密文
- Do the Untwist(模拟)
- POJ 1317 Do the Untwist 已被翻译
- (ZJU-2006复试)-ZOJ-1006-Do the Untwist
- hdu 1129 Do the Untwist
- POJ1317 Do the Untwist
- ZJU 1006 Do the Untwist
- ZOJ1006 Do the Untwist
- Do the Untwist
- Do the Untwist
- [ZOJ 1006] Do the Untwist (模拟实现解密)
- Do the Untwist (1006)
- ZOJ 1006 Do the Untwist 加密解密 模拟
- 1006 Do the Untwist
- joj1019 Do the Untwist
- ACM/ICPC ZOJ1006-Do the Untwist 解题代码