22251_Word

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

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

Pro.ID

22251

Title

Word

Title链接

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

AC

1

Submit

1

Ratio

100.00%

时间&空间限制

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

    Dr. R. E. Wright's class was studying modified L-Systems. Let us explain necessary details. As a model let us have words of length n over a two letter alphabet { a, b }. The words are cyclic, this means we can write one word in any of n forms we receive by cyclic shift, whereby the first and the last letters in the word are considered to be neighbours.

    Rewriting rules rewrite a letter at a position i, depending on letters at the positions i-2, i, i+1. We rewrite all letters of the word in one step. When we have a given starting word and a set of rewriting rules a natural question is: how does the word look after s rewriting steps?

    Help Dr. R. E. Wright and write a program which solves this task.

    输入

    There are several blocks in the input file, each describing one system. There is an integer number n, 2 < n < 16 the length of the input word in the first line. There is a word in the next line. The word contains only lowercase letters a and b. There are four characters c1  c2  c3  c4 in the next eight lines. Each quadruple represents one rewriting rule with the following meaning: when the letter at the position i - 2 is c1 and the letter at the position i is c2 and the letter at the position i + 1 is c3 then the letter at the position i after rewriting will be c4. Rewriting rules are correct and complete. There is an integer number s,  0 ≤ s ≤ 2000000000, in the last line of the block.

    输出

    Description

    Dr. R. E. Wright's class was studying modified L-Systems. Let us explain necessary details. As a model let us have words of length n over a two letter alphabet { a, b }. The words are cyclic, this means we can write one word in any of n forms we receive by cyclic shift, whereby the first and the last letters in the word are considered to be neighbours.

    Rewriting rules rewrite a letter at a position i, depending on letters at the positions i-2, i, i+1. We rewrite all letters of the word in one step. When we have a given starting word and a set of rewriting rules a natural question is: how does the word look after s rewriting steps?

    Help Dr. R. E. Wright and write a program which solves this task.

    Input

    There are several blocks in the input file, each describing one system. There is an integer number n, 2 < n < 16 the length of the input word in the first line. There is a word in the next line. The word contains only lowercase letters a and b. There are four characters c1  c2  c3  c4 in the next eight lines. Each quadruple represents one rewriting rule with the following meaning: when the letter at the position i - 2 is c1 and the letter at the position i is c2 and the letter at the position i + 1 is c3 then the letter at the position i after rewriting will be c4. Rewriting rules are correct and complete. There is an integer number s,  0 ≤ s ≤ 2000000000, in the last line of the block.

    Output

    There is one line corresponding to each block of the input file. The line contains a word which we receive after s rewriting steps from the corresponding starting word using given rewriting rules. As we mentioned above, the word can be written in any of n cyclic shifted forms. The output file contains the lexicographically smallest word, assuming that a < b.

    Sample Input

    5
    aaaaa
    aaab
    aabb
    abab
    abbb
    baab
    babb
    bbab
    bbbb
    1

    Sample Output

    bbbbb

    Source

    样例输入

    5
    aaaaa
    aaab
    aabb
    abab
    abbb
    baab
    babb
    bbab
    bbbb
    1

    样例输出

    bbbbb

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部