10264_ShiftCipher

2022-5-16 18:16| 发布者: Hocassian| 查看: 79| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-3-89504710899799-Problem List-采集的数据-后羿采集器.html

Pro.ID

10264

Title

Shift Cipher

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=10264

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    A cryptosystem is a method to convert a message into a cipher, which is difficult to understand by unauthorized people. Assume that both the message and the cipher are strings over the alphabet {a, b, …, z}.

    A shift cipher is a cryptosystem that shifts each character in the message by k positions. For example, if k = 3, then a is converted into d, b into e, …, x into a, y into b, and z into c. The number k is called the key of the cryptosystem.

    To make the cipher more difficult to understand, spaces and all punctuations are removed from the message before encryption. For example, assume that k = 3, the message:

    we will meet at midnight.

    is encrypted into the cipher:

    zhzloophhwdwplgqljkw

    For simplicity, we assume that a message is recovered if spaces are inserted into the text so that each word separated by spaces is a word in the dictionary. Given a cipher text write a program to recover the message. You may assume that each cipher is less than 256 characters, and each word used in the message appears in the dictionary. The dictionary is located at the very beginning of the input, succeeded by a single blank line. This dictionary is plain text; each line contains a word. There are words with capital or special letters in the dictionary. These words will not be used in our system. It is not necessary to check if the sentence is grammatically correct or not. The answer will be considered correct if no adjacent words are single character and the average number of characters in the words is greater than 2.

    输入

    The input data is a set of ciphers. Each cipher is written in a line. A line containing only the character 0 signals the end of a test data.

    输出

    Description

    A cryptosystem is a method to convert a message into a cipher, which is difficult to understand by unauthorized people. Assume that both the message and the cipher are strings over the alphabet {a, b, …, z}.

    A shift cipher is a cryptosystem that shifts each character in the message by k positions. For example, if k = 3, then a is converted into d, b into e, …, x into a, y into b, and z into c. The number k is called the key of the cryptosystem.

    To make the cipher more difficult to understand, spaces and all punctuations are removed from the message before encryption. For example, assume that k = 3, the message:

    we will meet at midnight.

    is encrypted into the cipher:

    zhzloophhwdwplgqljkw

    For simplicity, we assume that a message is recovered if spaces are inserted into the text so that each word separated by spaces is a word in the dictionary. Given a cipher text write a program to recover the message. You may assume that each cipher is less than 256 characters, and each word used in the message appears in the dictionary. The dictionary is located at the very beginning of the input, succeeded by a single blank line. This dictionary is plain text; each line contains a word. There are words with capital or special letters in the dictionary. These words will not be used in our system. It is not necessary to check if the sentence is grammatically correct or not. The answer will be considered correct if no adjacent words are single character and the average number of characters in the words is greater than 2.

    Input

    The input data is a set of ciphers. Each cipher is written in a line. A line containing only the character 0 signals the end of a test data.

    Output

    The output is the key k and the recovered message for each of the cipher. Print the solution of each test case in a line. If the solution is not unique, print the solution with minimum number of words. If there is no solution, print “NO SOLUTIONS”.

    Sample Input
    we
    will
    meet
    at
    midnight
    
    zhzloophhwdwplgqljkw
    lowder
    0
    Sample Output
    k=3: we will meet at midnight
    NO SOLUTIONS
    Source

    样例输入

    we
    will
    meet
    at
    midnight
    
    zhzloophhwdwplgqljkw
    lowder
    0

    样例输出

    k=3: we will meet at midnight
    NO SOLUTIONS

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部