17.04.29 Bacon's Cipher
来源:互联网 发布:卡尔曼 知乎 编辑:程序博客网 时间:2024/06/05 14:51
Bacon's Cipher
HDU - 4144Bacon's cipher or the Baconian cipher is a method of steganography (a method of hiding a secret message as opposed to a true cipher) devised by Francis Bacon. A message is concealed in the presentation of text, rather than its content.
As we all know, each letter has its position in the alphabet, ‘A’ is 0, ‘B’ is 1, ‘C’ is 2…and so on. And each number can be represented in binary code, for example, 2 is ‘10’ in binary system. Then we expand the binary code to five digits by adding leading zeros, then 10 becomes 00010. Now we can use this number to encode. To simplify the question, we define the rules as below:
0 corresponds to a random uppercase letter and 1 corresponds to a random number, so after encoding, 00010 ( ‘C’ ) is transformed to ABC1D or JUG9N.
To decode, do the opposite way around.
As we all know, each letter has its position in the alphabet, ‘A’ is 0, ‘B’ is 1, ‘C’ is 2…and so on. And each number can be represented in binary code, for example, 2 is ‘10’ in binary system. Then we expand the binary code to five digits by adding leading zeros, then 10 becomes 00010. Now we can use this number to encode. To simplify the question, we define the rules as below:
0 corresponds to a random uppercase letter and 1 corresponds to a random number, so after encoding, 00010 ( ‘C’ ) is transformed to ABC1D or JUG9N.
To decode, do the opposite way around.
Input
The first line contains a positive number l, represents the length of the encoded string. L<=10000 and can be divided by 5. The second line is the encoded string.
Output
The original string.
Sample Input
35
ON1E2H5Q39AK2TGIC9ERT39B2P423L8B20D
Sample Output
FLEENOW
————————————
读一个二维字符串,每行五个字符,一行转换成一串二进制,再将二进制转成十进制,再输出字符。
一开始分割字符串的时候总是出错,是因为scanf("%s",ss)读了input第一行末尾的\n,醉了。
#include <stdio.h>#include <math.h>#include <algorithm>using namespace std;int to10(char ss[5]){ int res=0,i; for(i=4;i>=0;i--) { res+=ss[i]*pow(2,(4-i)); } return res;}int main(){ int n; while(~scanf("%d\n",&n)) { char a[2001][5]; for(int i=0;i<(n/5);i++) { int j; for(j=0;j<5;j++) { scanf("%c",&a[i][j]); if(a[i][j]>='A'&&a[i][j]<='Z')a[i][j]=0; else a[i][j]=1; } printf("%c",to10(a[i])+'A'); } printf("\n"); } return 0;}
0 0
- 17.04.29 Bacon's Cipher
- HDU4144:Bacon's Cipher
- hdu4144 Bacon's Cipher
- HDU4144 Bacon's Cipher
- HDU 4144 Bacon's Cipher
- HDU 4144 Bacon's Cipher
- Bacon's Cipher hdu4144 水题
- hdu 4144 Bacon's Cipher
- 【字符串】hdu4144 Bacon's Cipher
- Ural 1590. Bacon’s Cipher 后缀数组
- HDU 4144Bacon's Cipher (解码)
- HDU菜鸟杯比赛第二题Bacon's Cipher
- 2011百校联动“菜鸟杯”程序设计公开赛&&Bacon's Cipher
- 1042 W's Cipher
- POJ_1107_W's Cipher
- hdu4144Bacon's Cipher
- POJ1107 W's Cipher
- ZOJ1042-W`s Cipher
- Matlab求解线性方程组Ax=b的几种常见方法Matlab求解线性方程组Ax=b的几种常见方法
- Redis3.2.8 基本安装配置
- Vijos P1001 谁拿了最多奖学金【分段计算处理】(Bailian2715)
- CENTOS7安装部署ORACLE11G
- java/eclipse调用matlab功能函数
- 17.04.29 Bacon's Cipher
- TensorFlow安装(windows环境下)
- CodeVS 1044 拦截导弹(ACM)
- Unity判断一个物体是否在屏幕内外
- 第2章 人月神话
- FastDFS5.0.9基本安装配置
- nginx学习
- proteus第一个工程 流水灯实验
- java-finally块和return执行先后顺序