Literature Lesson - CodeForces 139C 水题

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 than k vowels, then such line can't rhyme with any other line. For example, if k = 1, lines commit and hermit rhyme (the corresponding suffixes equal it), 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 by aaaa).

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 is aaaa. 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 and k (1 ≤ n ≤ 25001 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104.

If we assume that the lines are numbered starting from 1, then the first quatrain contains lines number 1234; the second one contains lines number 5678; 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.

Sample test(s)
input
1 1
day
may
sun
fun
output
aabb
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
Note

In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".


题意:k表示行取倒数第k个韵母后面的后缀,包括这个韵母,每四行为一组,每组这些后缀看是否相同,使得其满足aaaa,aabb,abab,abba几种情况。然后对于每组,使得整首诗都满足同样的方式,注意aaaa可以变换到其他三种形式。输出这一形式,如果不满足同一个形式,输出NO。

思路:就是比较后缀……【可怜我最开始把num设成char类型了,结果WA了好久……~~~~(>_<)~~~~ 

AC代码如下:

#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
char s1[100100],s2[5][100100];
int num[5];
int main()
{ int i,j,k,n,t,p,p2,len,f12,f13,f14,f23,f24,f34,T;
  scanf("%d%d",&n,&k);
  memset(num,0,sizeof(num));
  bool flag=true;
  for(T=1;T<=n;T++)
  { for(t=1;t<=4;t++)
    { scanf("%s",s1);
      len=strlen(s1);
      p=k;
      for(i=len;i>=1 && p>0;i--)
      { s2[t][len-i]=s1[i-1];
        if(s1[i-1]=='a' ||s1[i-1]=='e' ||s1[i-1]=='i' ||s1[i-1]=='o' ||s1[i-1]=='u')
         p--;
      }
      s2[t][len-i]='\0';
      if(p>0)
       flag=false;
    }
    f12=strcmp(s2[1],s2[2]);
    f13=strcmp(s2[1],s2[3]);
    f14=strcmp(s2[1],s2[4]);
    f23=strcmp(s2[2],s2[3]);
    f24=strcmp(s2[2],s2[4]);
    f34=strcmp(s2[3],s2[4]);
    if(f12==0 && f34==0 && f13==0)
     num[1]=num[1]+1;
    else if(f12==0 && f34==0)
     num[2]=num[2]+1;
    else if(f13==0 && f24==0)
     num[3]=num[3]+1;
    else if(f14==0 && f23==0)
     num[4]=num[4]+1;
    else
     flag=false;
  }
  int ans=0;
  for(i=2;i<=4;i++)
   if(num[i]>0)
    ans++;
  if(ans>1)
  flag=false;
  if(!flag)
   printf("NO\n");
  else
  { if(num[2]>0)
     printf("aabb\n");
    else if(num[3]>0)
     printf("abab\n");
    else if(num[4]>0)
     printf("abba\n");
    else
     printf("aaaa\n");
  }
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值