CodeForces 139C Literature Lesson

  这个题,读懂了就是水,读不懂就没办法下手,论英语阅读的重要性...只有五种形式,第一种万能型aaaa,是另外3种的特殊情况,第二种克莱里林四行打油诗aabb形式,第三种是交替的abab形式,第四种是封闭的abba形式,第五种就是NO.题目的意思就是给我们四个原串,让我们counting from the end(从后往前数)找到第k个元音字母,从这个位置截取原串的suffixes(后缀),形成四个新串,判断这四个新串符合以上五中情况中的哪一个.如果原串不足k个元音字母,那情况直接就是no.在判断的时候需要注意aaaa不用管,它可以与任意情况重合(除NO以外),而剩下的4中任意两种都不可重合,代码及注释如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
bool mark[10];///0=aaaa,1=aabb,2=abab,3=abba,4=NO
char str[10110],newstr[5][10110];
char output[5][5] = {"aabb","abab","abba"};
void Judge()
{
    if( !strcmp(newstr[0],newstr[1])&& !strcmp(newstr[0],newstr[2])&& !strcmp(newstr[0],newstr[3]))
        mark[0] = 1;
    else if(!strcmp(newstr[0],newstr[1])&&!strcmp(newstr[2],newstr[3])) mark[1] = 1;
    else if(!strcmp(newstr[0],newstr[2])&&!strcmp(newstr[1],newstr[3])) mark[2] = 1;
    else if(!strcmp(newstr[0],newstr[3])&&!strcmp(newstr[1],newstr[2])) mark[3] = 1;
    else mark[4] = 1;
}
bool Is_vowels(char a)
{
    if(a==‘a‘||a==‘e‘||a==‘i‘||a==‘o‘||a==‘u‘) return true;
    return false;
}
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    memset(mark,0,sizeof(mark));
    while(n--)
    {
        //memset(newstr,0,sizeof(newstr));
        int tot,ok=1;
        for(int i = 0; i < 4; i++)
        {
            scanf("%s",str);
            int lens = strlen(str),pos;
            tot=0;
            for(int j = lens-1; j >= 0; j--)
            {
                if(Is_vowels(str[j]))
                {
                    tot++;
                }
                if(tot == k)
                {
                    pos = j;
                    break;
                }
            }
            if(tot < k)
            {
                mark[4] = 1;
                ok = 0;
            }
            if(tot == k)///这个判断必须要有,否则RE
            {
                for(int j = pos; j < lens; j++)
                {
                    newstr[i][j-pos] = str[j];
                }
                newstr[i][lens-pos] = ‘\0‘;///换行符结束标识
            }
        }
        if(ok)
            Judge();
    }
    if(mark[4]) puts("NO");///注意判断顺序
    else
    {
        bool flag = true;
        for(int i = 1; i <= 3; i++)
        {
            for(int j = i+1; j <= 3; j++)
            {
                if(mark[i] && mark[j])
                {
                    flag = false;
                    break;
                }
            }
        }
        if(!flag) puts("NO");
        else if(flag)
        {
            for(int i = 1; i <= 3; i++)
            {
                if(mark[i])
                {
                    printf("%s\n",output[i-1]);
                    flag = false;
                    break;
                }
            }
            if(flag)
            {
                puts("aaaa");
            }
        }
    }
    return 0;
}
时间: 2024-11-04 02:26:57

CodeForces 139C Literature Lesson的相关文章

CodeForces - 316D3 PE Lesson

Discription Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises

CF758C Unfair Poll

题意: On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others. Seating in the class looks like a rectangle, where n rows with m pupils in each. The teacher asks pupils in the following or

CodeForces 842D Vitya and Strange Lesson

题目:http://codeforces.com/problemset/problem/842/D 题意:给你n个数,m次查询,每次将数组全部异或一个数后,求没出现过的最小自然数 要求异或后的最小值我们可以用字典树来解决 而每次对数组异或可以替换每次对异或值异或 之后贪心的选取 每次都走左子树,如果左子树满了,才走右子树,这样就能保证是最小 #include<iostream> #include<cstdio> #include<cstring> #include<

Codeforces 37D Lesson Timetable - 组合数学 - 动态规划

题目传送门 神奇的门I 神奇的门II 题目大意 有$n$组学生要上课2次课,有$m$个教室,编号为$1$到$m$.要确定有多少种不同的安排上课的教室的方案(每组学生都是本质不同的),使得它们满足: 每组学生第一次上课的教室的编号小于等于第二次上课的教室的编号. 第$i$间教室在第一次上课时,恰好有$x_{i}$组学生在场. 第$i$间教室在某次上课时,中间包含的学生组数不能超过$y_{i}$. 输出答案模$10^{9} + 7$. 因为第一次上课恰好有多少人,所以这个方案数是可以直接用组合数,暂

C. Substring Game in the Lesson ( Codeforces Round #586 (Div. 1 + Div. 2) )

Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string ss and a number kk (0≤k<|s|0≤k<|s|). At the beginning of the game, players are giv

Code is not literature

http://www.gigamonkeys.com/code-reading/ I have started code reading groups at the last two companies I’ve worked at, Etsy and Twitter, and some folks have asked for my advice about code reading and running code reading groups. Tl;dr: don’t start a c

Codeforces Round #277 E. LIS of Sequence(486E) 树状数组乱搞

http://codeforces.com/contest/486/problem/E E. LIS of Sequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The next "Data Structures and Algorithms" lesson will be about Longest I

Codeforces 66C

C - Petya and File System Time Limit:3000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 66C Appoint description:  System Crawler  (Nov 8, 2016 10:35:35 PM) Description Recently, on a programming lesso

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas