1654. Shift Cipher

单点时限: 2.0 sec

内存限制: 256 MB

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

Since there are only 26 different keys, given a cipher text, it is easy to convert each character back to the original message. However, by using a computer, it may not be trivial to insert spaces so that the original message can be recovered automatically.

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 in

usr/share/dict/american-english.

This dictionary is a text file; 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. You may want to look at the dictionary before programming. 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 lines. A line containing only the character ‘0’ signals the end of a test data.

输出格式

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”.

样例

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

1 人解决,4 人已尝试。

1 份提交通过,共有 6 份提交。

9.9 EMB 奖励。

创建: 17 年,3 月前.

修改: 7 年,3 月前.

最后提交: 1 年,5 月前.

来源: kaohsiung 2006

题目标签