HDU 2707 Steganography 字符串处理
来源:互联网 发布:淘宝女打底衫 编辑:程序博客网 时间:2024/06/12 23:10
Problem Description
In cryptography, the goal is to encrypt a message so that, even if the the message is intercepted, only the intended recipient can decrypt it. In steganography, which literally means "hidden writing", the goal is to hide
the fact that a message has even been sent. It has been in use since 440 BC. Historical methods of steganography include invisible inks and tatooing messages on messengers where they can't easily be seen. A modern method is to encode a message using the least-significant bits of the RGB color values of pixels in a digital image.
For this problem you will uncover messages hidden in plain text. The spaces within the text encode bits; an odd number of consecutive spaces encodes a 0 and an even number of consecutive spaces encodes a 1. The
four texts in the example input below (terminated by asterisks) encode the following bit strings: 11111, 000010001101101, 01, and 000100010100010011111. Each group of five consecutive bits represents a
binary number in the range 0–31, which is converted to a character according to the table below. If the last group contains fewer than five bits, it is padded on the right with 0's.
" " (space) 0
"A" – "Z" 1–26
"'" (apostrophe) 27
"," (comma) 28
"-" (hyphen) 29
"." (period) 30
"?" (question mark) 31
The first message is 111112 = 3110 = "?". The second message is (00001, 00011, 01101)2 = (1, 3, 13)10 =
"ACM". The third message is 010002 = 810 = "H", where the underlined 0's are padding bits. The fourth message is (00010, 00101, 00010, 01111, 10000)2 = (2, 5, 2, 15, 16)10 = "BEBOP".
Input
the fact that a message has even been sent. It has been in use since 440 BC. Historical methods of steganography include invisible inks and tatooing messages on messengers where they can't easily be seen. A modern method is to encode a message using the least-significant bits of the RGB color values of pixels in a digital image.
For this problem you will uncover messages hidden in plain text. The spaces within the text encode bits; an odd number of consecutive spaces encodes a 0 and an even number of consecutive spaces encodes a 1. The
four texts in the example input below (terminated by asterisks) encode the following bit strings: 11111, 000010001101101, 01, and 000100010100010011111. Each group of five consecutive bits represents a
binary number in the range 0–31, which is converted to a character according to the table below. If the last group contains fewer than five bits, it is padded on the right with 0's.
" " (space) 0
"A" – "Z" 1–26
"'" (apostrophe) 27
"," (comma) 28
"-" (hyphen) 29
"." (period) 30
"?" (question mark) 31
The first message is 111112 = 3110 = "?". The second message is (00001, 00011, 01101)2 = (1, 3, 13)10 =
"ACM". The third message is 010002 = 810 = "H", where the underlined 0's are padding bits. The fourth message is (00010, 00101, 00010, 01111, 10000)2 = (2, 5, 2, 15, 16)10 = "BEBOP".
Input
The input consists of one or more texts. Each text contains one or more lines, each of length at most 80 characters, followed by a line containing only "*" (an asterisk) that signals the end of the text. A line containing only "#" signals the end of the input. In addition to spaces, text lines may contain any ASCII letters, digits, or punctuation, except for "*" and "#", which are used only as sentinels.
Output
For each input text, output the hidden message on a line by itself. Hidden messages will be 1–64 characters long.
Note: Input text lines and output message lines conform to all of the whitespace rules listed in item 7 of Notes to Teams except that there may be consecutive spaces within a line. There will be no spaces at the beginning or end of a line.
Note: Input text lines and output message lines conform to all of the whitespace rules listed in item 7 of Notes to Teams except that there may be consecutive spaces within a line. There will be no spaces at the beginning or end of a line.
Sample Input
Programmer,I would like to seea questionmark.*Behold, there is more to me than you mightthink when you read me the first time.*Symbol for hydrogen?*A B C D E F G H I J K L M N O P Q R S T U V*#
Sample Output
?ACMHBEBOP
题意 数间隔空格数,单数为0,偶数为1 然后每5个 变为一个整数<0,31> 在将整数对应的符号输出
注意输出的字符串首尾不能有空格
#include<iostream>using namespace std;#include<stdio.h>#include<string.h>int i=0,flag=0,fristc=0;int bit[5000],shu[1000];void output(int n){ switch(n) { case 0 : printf(" ");break; case 27: printf("'");break; case 28: printf(",");break; case 29: printf("-");break; case 30: printf(".");break; case 31: printf("?");break; default : printf("%c",n-1+'A'); }}void translate(int n){ int k=0; for(int i=0;i<n;i++) bit[i]=!bit[i]; if(n%5) n=n-n%5+5; // Pad on the right with 0's. for(int i=4; i<n; i+=5,k++) { int ans=0,jz=1; for(int j=i; j>=i-4; j--) { if(bit[j]==1) ans+=jz; jz*=2; } shu[k]=ans; } int i=0; //No spaces at the beginning or end of a line while(shu[i]==0) i++; while(shu[k-1]==0) k--; for(int j=i;j<k;j++) output(shu[j]);}void input(char c){ if(c=='*') { translate(i+1),cout<<endl; i=fristc=flag=0,memset(bit,0,sizeof(bit)); //初始化 } if(c==' ') { if(fristc) i++; bit[i]=!bit[i]; fristc=0,flag=1; } else if(flag) fristc=1;}int main(){ char c; while((c=getchar())!='#') input(c); return 0;}
- HDU 2707 Steganography 字符串处理
- hdu 2707 Steganography 模拟题
- HDU——2707 Steganography
- UVALive 4174 Steganography 字符串处理 密码学
- Steganography
- Steganography
- Steganography
- HDU-1039 字符串处理
- hdu 1062 字符串处理
- hdu 1048 字符串处理
- hdu 1062 字符串处理
- hdu 1106 字符串处理
- HDU 5056 字符串处理
- 字符串处理 hdu 1048
- HDU 1048 字符串处理
- HDU 1106字符串处理
- Steganography Revealed
- HDU 1020 Encoding (字符串处理)
- java保留两位小数4种方法
- Android Permission Denial: starting Intent
- 接收数据并显示实时波形图---资料收集
- Android Robotium自动化测试二
- android中intent带Uri传输时中文的乱码、android 获取文件名乱码处理方法
- HDU 2707 Steganography 字符串处理
- DWR使用总结
- PHP数据库永久连接
- spring 管理servlet
- 无法从“void (__thiscall XXX::* )(void)”转换为“cocos2d::SEL_SCHEDUL 错误总结
- java_web学习第七天(jsp技术)
- mpegts代码分析
- visual assist x 代码颜色失效解决办法
- c++ 操作mysql