eolymp
bolt
Попробуйте наш новый интерфейс для отправки задач
Задачи

Double Trouble

Double Trouble

Alice Catherine Morris and her sister Irene Barbara frequently send each other e-mails. Ever wary of interceptions and wishing to keep their correspondence private, they encrypt their messages in two steps. After removing all nonalphabetic characters and converting all letters to upper case, they: 1) replace each letter by the letter s positions after it in the alphabet (\textbf{1} ≤ \textbf{s} ≤ \textbf{25})|we call this a \textit{shift} by s - and then, 2) divide the result of step \textbf{1} into groups of m letters and reverse the letters in each group (\textbf{5} ≤ \textbf{m} ≤ \textbf{20}). If the length of the message is not divisible by \textbf{m}, then the last \textbf{k} (less than \textbf{m}) letters are reversed. For example, suppose \textbf{s = 2} and \textbf{m = 6}. If the plaintext were \textbf{Meet me in St. Louis, Louis.} after removing unwanted characters and changing to upper case we get \textbf{MEETMEINSTLOUISLOUIS} We will call this the modi ed plaintext. We then shift each letter by \textbf{2} (\textbf{Y} would be replaced with \textbf{A} and \textbf{Z} would be replaced by \textbf{B}, here), getting the intermediate result: \textbf{OGGVOGKPUVNQWKUNQWKU} And nally reverse every group of \textbf{6} letters: \textbf{GOVGGOQNVUPKWQNUKWUK} Note the last two letters made up the last reversed group. As is customary, we write the result in groups of \textbf{5} letters. So the ciphertext would be: \textbf{GOVGG OQNVU PKWQN UKWUK} Alas, it's not so hard to nd the values for \textbf{s} and \textbf{m} when the ciphertext is intercepted. In fact it's even easier if you know a crib, which is a word in the modi ed plaintext. In the above example, \textbf{LOUIS} would be a crib. Your job here is to find \textbf{s} and \textbf{m} when presented with a ciphertext and a crib. \InputFile Input will consist of multiple problem instances. The first line of input will contain a positive integer indicating the number of problem instances. The input for each problem will consist of multiple lines. The first line of input for a problem will contain the integer \textbf{n} (2\textbf{0} ≤ \textbf{n} ≤ \textbf{500}) which is equal to the number of characters in the ciphertext. The following lines will contain the ciphertext, all upper case in groups of \textbf{5} letters separated by a single space. (The last group of letters may contain fewer than \textbf{5} letters.) There will be \textbf{10} groups of letters per line, except possibly for the last line of ciphertext. The input line following the last line of ciphertext will contain the crib; a single word consisting of between \textbf{4} and \textbf{10} (inclusive) upper case characters. \OutputFile Output will be two integers, \textbf{s} and \textbf{m} on a line, separated by a single space, indicating the encryption key that produces the crib, where \textbf{s} is the shift and \textbf{m} is the reversed group size. If there is more than one solution, output the one with smallest \textbf{s}. If there is more than one with the same \textbf{s}, output the one with smallest \textbf{m}. If no such \textbf{s} and \textbf{m} exist, output the message "\textbf{Crib is not encrypted.}".
Лимит времени 1 секунда
Лимит использования памяти 64 MiB
Входные данные #1
4
83
FIQMF IISFN QMFIB EOPFH FNQMV PSFIU IZNGP UPEUS BFPEP PEPPE
PPEPN QMFIP EOPIS FIQMF IBSFN QMFBE OPI
RHONDA
105
VDBMN DQDGS LNQEM ZLZRZ RNGVX ZALNA TERZV CZDGD MZQHZ GENKK
KONSC DJHKC KKZAD RZAXZ SNMRH GBHGV RZVDG XZRNS XZKOS ZCNNF
SHFMH
BOMBAY
50
QFNWX YQFNW YSAQX FYNWY XQFNW SXYQF FXNYS AXYQF NASXY QFNAX
HEAVEN
20
GOVGG OQNVU PKWQN UKWUK
LOUIS
Выходные данные #1
1 6
25 6
Crib is not encrypted.
2 6
Источник ACM ICPC East Central Regional Contest 2000