admin管理员组

文章数量:1630197

A. Literature Lesson time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes.

Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels.

Two lines rhyme if their suffixes that start from the k-th vowels (counting from the end) match. If a line has less thank vowels, then such line can't rhyme with any other line. For example, ifk = 1, lines commit andhermit rhyme (the corresponding suffixes equalit), and ifk = 2, they do not rhyme (ommit ≠ ermit).

Today on a literature lesson Vera learned that quatrains can contain four different schemes of rhymes, namely the following ones (the same letters stand for rhyming lines):

  • Clerihew (aabb);
  • Alternating (abab);
  • Enclosed (abba).

If all lines of a quatrain pairwise rhyme, then the quatrain can belong to any rhyme scheme (this situation is represented byaaaa).

If all quatrains of a poem belong to the same rhyme scheme, then we can assume that the whole poem belongs to this rhyme scheme. If in each quatrain all lines pairwise rhyme, then the rhyme scheme of the poem isaaaa. Let us note that it doesn't matter whether lines from different quatrains rhyme with each other or not. In other words, it is possible that different quatrains aren't connected by a rhyme.

Vera got a long poem as a home task. The girl has to analyse it and find the poem rhyme scheme. Help Vera cope with the task.


Input

The first line contains two integers n andk (1 ≤ n ≤ 2500,1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed104.

If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number1,2,3,4; the second one contains lines number5,6, 7, 8; and so on.


Output

Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.









Input
1 1
day
may
gray
way
Output
aaaa
Input
2 1
a
a
a
a
a
a
e
e
Output
aabb
Input
2 1
day
may
sun
fun
test
hill
fest
thrill
Output
NO
 
   
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main()
{
    int N,K,len,flag[2505],i,last,num;
    string s[5],match[5];
    scanf("%d%d",&N,&K);
    for(i = 1;i <= N; i++)
    {
        for(int j = 1;j <= 4; j++)
        {
            cin>>s[j];
            len = s[j].size();

                num = 0;
                for(last = len-1;last>=0;last--)
                {
                    if(s[j][last]=='a'||s[j][last]=='e'
                       ||s[j][last]=='i'||s[j][last]=='o'
                       ||s[j][last]=='u')num++;
                       if(num==K)break;
                }
            if(num!=K)break;
            match[j] = s[j].substr(last,len);
        }
        if(num!=K)break;
        if(match[1]pare(match[2])==0
           &&match[3]pare(match[4])==0
           &&match[1]pare(match[3])==0)flag[i] = 0;
        else if(match[1]pare(match[2])==0
           &&match[3]pare(match[4])==0)flag[i] = 1;
        else if(match[1]pare(match[3])==0
           &&match[2]pare(match[4])==0)flag[i] = 2;
        else if(match[1]pare(match[4])==0
           &&match[3]pare(match[2])==0)flag[i] = 3;
        else break;
        if(i==1)continue;
        if(flag[i]!=flag[i-1]&&flag[i]!=0&&flag[i-1]!=0)break;
        if(flag[i]==0)flag[i] = flag[i-1];
    }
    if(i!=N+1)cout<<"NO"<<endl;
    else if(flag[N]==0)cout<<"aaaa"<<endl;
    else if(flag[N]==1)cout<<"aabb"<<endl;
    else if(flag[N]==2)cout<<"abab"<<endl;
    else if(flag[N]==3)cout<<"abba"<<endl;
    return 0;
}


 
   
 
   

本文标签: Literaturelesson