程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> HDU4144:Bacons Cipher

HDU4144:Bacons Cipher

編輯:C++入門知識

Problem Description
Bacon'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.

 


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

 

題意:給出一串密碼,字母代表0,數字代表1,每五個構成一個二進制,該二進制的值代表一個字母,求出明文

思路:水題,最近忙於考試,先A道水題來找找感覺

 

 

#include <stdio.h>
#include <string.h>

int num(char c)
{
    if(c>='A' && c<='Z')
    return 0;
    else return 1;
}

int main()
{
    int n,i,k;
    char a[10005];
    while(~scanf("%d%s",&n,a))
    {
        for(i = 0;i<n;i+=5)
        {
            k = 0;
            if(num(a[i]))
            k+=16;
            if(num(a[i+1]))
            k+=8;
            if(num(a[i+2]))
            k+=4;
            if(num(a[i+3]))
            k+=2;
            if(num(a[i+4]))
            k++;
            printf("%c",k+'A');
        }
        printf("\n");
    }

    return 0;
}

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved