21984_Littera

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

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

Pro.ID

21984

Title

Littera

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    Littera is an encryption system used in ancient Russian manuscripts. Several variations of littera are known, and we investigate one used on the Latin alphabet.

    The plaintext is encrypted using a short keyword consisting of lowercase Latin letters. Only Latin letters are replaced during the encryption, all other symbols remain unchanged. The letters are divided into blocks so that all (except for the last one, possibly) have the same length as the key. If a1 is the position of the first letter of the plaintext in the alphabet and b1 is the position of the first letter of the key, then the first letter of the text is replaced with the letter on the position a1+b1 of the alphabet (if a1+b1 > 26, the letter a1+b1-26 is used instead). The case of the letters of the plaintext is preserved. The following letters of each block are encrypted in the same manner , using the corresponding letter of the key.

    For example, let the plaintext be "crusader" and the key "bow". Then the first letter of the ciphertext is 'e' (the position of the first letter of the plaintext is 3 and the position of the first letter of the key is 2, thus the first letter of the ciphertext must be from the position 5 of the alphabet). The second letter of the plaintext is replaced with 'g' (18+15=33, 33-26=7). Continuing in the same manner , the whole ciphertext turns out to be "egrupagg". Note that in this case each letter of the plaintext is always represented by the same letter in the ciphertext, but this is a mere coincidence -- it does not happen when the distance between the occurrences of a letter in the plaintext is not a multiple of the length of the key!

    You are given two fragments of a document: one in plaintext, the other encrypted using the above system. The lengths of the fragments are equal and it is known that the first character of the ciphertext is obtained from the first character of the plaintext. It is also known that the number of letters in the given fragments is no less than the length of the keyword. It is, however , not known whether the fragments start at the beginning of a document!

    Based on the given data, derive the shortest possible keyword!

    输入

    The first line of the input contains N (1 ≤ N ≤ 106) -- the number of characters in each fragment. It is followed by the two text fragments, first the plaintext and then the ciphertext. The ciphertext always starts from a new line, but each of the fragments may be arbitrarily split across several lines.

    输出

    Description

    Littera is an encryption system used in ancient Russian manuscripts. Several variations of littera are known, and we investigate one used on the Latin alphabet.

    The plaintext is encrypted using a short keyword consisting of lowercase Latin letters. Only Latin letters are replaced during the encryption, all other symbols remain unchanged. The letters are divided into blocks so that all (except for the last one, possibly) have the same length as the key. If a1 is the position of the first letter of the plaintext in the alphabet and b1 is the position of the first letter of the key, then the first letter of the text is replaced with the letter on the position a1+b1 of the alphabet (if a1+b1 > 26, the letter a1+b1-26 is used instead). The case of the letters of the plaintext is preserved. The following letters of each block are encrypted in the same manner , using the corresponding letter of the key.

    For example, let the plaintext be "crusader" and the key "bow". Then the first letter of the ciphertext is 'e' (the position of the first letter of the plaintext is 3 and the position of the first letter of the key is 2, thus the first letter of the ciphertext must be from the position 5 of the alphabet). The second letter of the plaintext is replaced with 'g' (18+15=33, 33-26=7). Continuing in the same manner , the whole ciphertext turns out to be "egrupagg". Note that in this case each letter of the plaintext is always represented by the same letter in the ciphertext, but this is a mere coincidence -- it does not happen when the distance between the occurrences of a letter in the plaintext is not a multiple of the length of the key!

    You are given two fragments of a document: one in plaintext, the other encrypted using the above system. The lengths of the fragments are equal and it is known that the first character of the ciphertext is obtained from the first character of the plaintext. It is also known that the number of letters in the given fragments is no less than the length of the keyword. It is, however , not known whether the fragments start at the beginning of a document!

    Based on the given data, derive the shortest possible keyword!

    Input

    The first line of the input contains N (1 ≤ N ≤ 106) -- the number of characters in each fragment. It is followed by the two text fragments, first the plaintext and then the ciphertext. The ciphertext always starts from a new line, but each of the fragments may be arbitrarily split across several lines.

    Output

    The first and only line of the output should contain the keyword. If there are several possible keywords, output the one earliest in the lexicographic order.

    Sample Input

    8
    Crusader
    Egrupagg

    Sample Output

    bow

    Source

    样例输入

    8
    Crusader
    Egrupagg

    样例输出

    bow

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部