Literature Lesson - CodeForces 139C 水题
2014-07-10 21:15
363 查看
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 ≤ 2500, 1 ≤ 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 1, 2, 3, 4;
the second one contains lines number 5, 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.
Sample test(s)
input
output
input
output
input
output
input
output
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代码如下:
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 ≤ 2500, 1 ≤ 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 1, 2, 3, 4;
the second one contains lines number 5, 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.
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"); } }
相关文章推荐
- Codeforces 632B Alice, Bob, Two Teams 【水题】
- CodeForces 540A Combination Lock (水题)
- Codeforces 631A Interview【模拟水题】
- CodeForces 703B Mishka and trip【水题】
- codeforces 659C C. Tanya and Toys(水题+map)
- CodeForces - 789A Anastasia and pebbles (水题)
- Codeforces 469B Chat Online(水题)
- Codeforces 660A Co-prime Array 【水题】
- codeforces 711A.Bus to Udayland 【水题】
- Codeforces 485B Valuable Resources(水题)
- Codeforces--237C--Primes on Interval(二分水题)
- Removing Columns - CodeForces 496 C 水题
- CodeForces 483B(水题)
- codeforces----2017 Hackatari Codeathon(A 暴力搜索 G概率)(水题DEH)
- CodeForces - 330B Road Construction(水题)
- CodeForces 670B(模拟)水题
- Codeforces-----140A---New Year Table---数学水题
- 【CodeForces 670A】Holidays(水题)
- Codeforces 602A Two Bases 【水题】
- CodeForces 723B Text Document Analysis (水题模拟)