杭电1129 Do the Untwist
来源:互联网 发布:五星大饭店知乎 编辑:程序博客网 时间:2024/05/16 00:48
杭电1129 Do the Untwist
杭电1129 题目很长,读了下来,其实意思就是把输入的字符串按规则转化为数组c中的元素,让你根据公式c[i] = (p[k*i mod n] - i) mod 28得到p中元素的值,我们可以把这个公式化简一下,就可得到对应的公式 c[i]=(p[k*i mod n])mod28-i mod28;所以p[k*i mod n]=(c[i] + i mod 28)mod 28;根据这个公式的到p数组中元素的值,再一次把数组转化为相应的字符输出就可以了。
Ac代码
Ac代码
#include<iostream>using namespace std;int main(){ int p[500], c[500]; char str[500]; int n; while (cin>>n) { memset(str, 0, sizeof(str)); if (n == 0) break; cin >> str; int len = strlen(str); for (int i = 0; i < len; i++) { if (str[i] == '_') { c[i] = 0; } else if (str[i] == '.') { c[i] = 27; } else { c[i] = str[i] - 'a' + 1; } } for (int i = 0; i < len; i++) { p[n*i%len] = (c[i] + i % 28)%28; } for (int i = 0; i < len; i++) { if (p[i] == 0) { str[i] = '_'; } else if (p[i] == 27) { str[i] = '.'; } else { str[i] = p[i] - 1 + 'a'; } } str[len] = '\0'; cout << str << endl; }return 0;}
0 0
- 杭电1129 Do the Untwist
- 杭电ACM1129——Do the Untwist~~解密 密文
- HDU 1129 Do the Untwist
- hdu 1129 Do the Untwist
- hdu 1129 Do the Untwist
- HDOJ HDU 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
- struts02-02
- 相关函数(暂存)
- 一天学会Git(一)
- 2015 多校赛 1002 (hdu 5289)
- poj 3723 Conscription (最小生成树)
- 杭电1129 Do the Untwist
- 黑马程序员_IO流
- 变态的debug问题-已解决
- PHP导出word(纯文字)
- Android之——申请应用系统管理员权限
- Intellij Idea如何识别某个文件的编码方案
- Java Jaxb JavaBean与XML互转
- Block
- 关于java基础--SQL驱动及JDBC连接