22118_TYLYLanguage

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

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

Pro.ID

22118

Title

TYLY Language

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

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

    WS (We Say), an organization of UQU, is a famous professional language research organization, which is well known for being good at improving, updating and creating languages. Recently, the organization is working out a language, TYLY (Tell you Love you), which is used to express love between lovers.
    The language TYLY is innovated on the basis of the current English Language. The words in TYLY is similar to English words, which is made up of alphabetic characters A, B ... Z or a, b ... z (case insensitive) and no word will be longer than 20 letters. Likewise, phrase is an important element in TYLY. A TYLY phrase is made up of exactly two different TYLY words and we call the first word in the phrase First Word and the second Last Word. For example, First Word of the phrase “Love you” is "Love", and Last Word is "you". Obviously, not every two words can form a phrase. The two words which can form a phrase must have special relations and the order of them is fixed. In TYLY, sentences are the most important. Each TYLY sentence is consisted of TYLY phrases which are end to end, that is to say, the First Word of any phrase (except the first phrase) in a TYLY sentence is the same with the Last Word of the phrase immediately previous to it. Moreover, no word will occur more than once in any sentence. In addition, for the sake of better expression, there is no punctuation in TYLY sentences.

    Now, let's see some TYLY words:
    I
    You
    Love
    Miss
    Very
    Much

    We define the following phrases:

    I Love
    Love You
    I Miss
    Miss You
    You Very
    Very Much

    So, we can have the following TYLY sentences:

    Love You
    I Love You
    Love You Very Much
    I Love You Very Much

    The sentences below are not correct TYLY sentences:

    I Love Very Much (phrases are not end to end)
    I You Very Much (no phrase "I You")
    I Love You, Very Much! (There is no punctuation in TYLY sentences.)

    The lovers are hoping to express love as much as possible, and WS creates the language TYLY just in order to help them, so the lovers hope to use the longest TYLY sentences. You are one member in WS. Given the words and the phrases, your job is to find the longest TYLY sentences and there is always at least one limited longest sentences.

    输入

    Input will contain several test cases. Each test case consists of several lines. The first line contains two integers M and N, representing respectively the number of words of the TYLY Language, and the number of phrases of the TYLY Language ( 1 <= M <= 100). In the following M lines, each line has a TYLY word. In the next N lines, each line has a TYLY phrase.

    The input data for the last test case will be followed by a line containing two zeros.

    输出

    Description
    WS (We Say), an organization of UQU, is a famous professional language research organization, which is well known for being good at improving, updating and creating languages. Recently, the organization is working out a language, TYLY (Tell you Love you), which is used to express love between lovers.
    The language TYLY is innovated on the basis of the current English Language. The words in TYLY is similar to English words, which is made up of alphabetic characters A, B ... Z or a, b ... z (case insensitive) and no word will be longer than 20 letters. Likewise, phrase is an important element in TYLY. A TYLY phrase is made up of exactly two different TYLY words and we call the first word in the phrase First Word and the second Last Word. For example, First Word of the phrase “Love you” is "Love", and Last Word is "you". Obviously, not every two words can form a phrase. The two words which can form a phrase must have special relations and the order of them is fixed. In TYLY, sentences are the most important. Each TYLY sentence is consisted of TYLY phrases which are end to end, that is to say, the First Word of any phrase (except the first phrase) in a TYLY sentence is the same with the Last Word of the phrase immediately previous to it. Moreover, no word will occur more than once in any sentence. In addition, for the sake of better expression, there is no punctuation in TYLY sentences.

    Now, let's see some TYLY words:
    I
    You
    Love
    Miss
    Very
    Much

    We define the following phrases:

    I Love
    Love You
    I Miss
    Miss You
    You Very
    Very Much

    So, we can have the following TYLY sentences:

    Love You
    I Love You
    Love You Very Much
    I Love You Very Much

    The sentences below are not correct TYLY sentences:

    I Love Very Much (phrases are not end to end)
    I You Very Much (no phrase "I You")
    I Love You, Very Much! (There is no punctuation in TYLY sentences.)

    The lovers are hoping to express love as much as possible, and WS creates the language TYLY just in order to help them, so the lovers hope to use the longest TYLY sentences. You are one member in WS. Given the words and the phrases, your job is to find the longest TYLY sentences and there is always at least one limited longest sentences.
    Input

    Input will contain several test cases. Each test case consists of several lines. The first line contains two integers M and N, representing respectively the number of words of the TYLY Language, and the number of phrases of the TYLY Language ( 1 <= M <= 100). In the following M lines, each line has a TYLY word. In the next N lines, each line has a TYLY phrase.

    The input data for the last test case will be followed by a line containing two zeros.

    Output

    For each test case in the input, you should output two lines. The first line is an integer, representing the length of the longest TYLY sentence (i.e. the number of words in the sentence). The second line is the longest TYLY sentence you find.

    There is exactly one space between the words.

    Sample Input
    6 6
    I
    You
    Love
    Miss
    Very
    Much
    I Love
    Love You
    I Miss
    Miss You
    You Very
    Very Much
    3 1
    a
    b
    c
    a b
    0 0
    Sample Output
    5
    I Miss You Very Much
    2
    a b
    Hint
    Special Judge
    Source

    样例输入

    6 6
    I
    You
    Love
    Miss
    Very
    Much
    I Love
    Love You
    I Miss
    Miss You
    You Very
    Very Much
    3 1
    a
    b
    c
    a b
    0 0

    样例输出

    5
    I Miss You Very Much
    2
    a b

    提示

    Special Judge


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部