HDOJ HDU 1129 Do the Untwist
来源:互联网 发布:2016年淘宝食品新规则 编辑:程序博客网 时间:2024/04/29 12:01
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’第 (0 * k) % 3 = 0 个字符 (c + 0)% 28 = 3 表中 3 还是 ‘c’
第 (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 28using 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; }}
阅读全文
0 0
- HDOJ HDU 1129 Do the Untwist
- HDU 1129 Do the Untwist
- hdu 1129 Do the Untwist
- hdu 1129 Do the Untwist
- hdoj 1129 Do the Untwist(数学公式+英文理解)
- 杭电1129 Do the Untwist
- Do the Untwist (1006)
- Do the Untwist
- 1006 Do the Untwist
- Do the Untwist
- ZOJ1006 Do the Untwist
- Do the Untwist
- Do the Untwist
- zoj1006-Do the Untwist
- C++ --Do the Untwist
- POJ1317 Do the Untwist
- ZOJ1006-Do the Untwist
- Do the Untwist
- 机器学习中的范数规则化之(一)L0、L1与L2范数
- linux时间
- 文件内容查阅
- 体检卡项目--前端架构配置
- python logging模块学习
- HDOJ HDU 1129 Do the Untwist
- 冒泡事件和捕获事件以及阻止冒泡和捕获方法的详解
- Django模型的Field Types总结
- JAVA实现n的全排列
- Android studio 沉浸式
- Git中设置全局ingore来忽略.DS_Store文件的方法
- camera daemon进程
- L0范数图像平滑
- Opencv开发环境配置