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] = '';///换行符结束标识
            }
        }
        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
",output[i-1]);
                    flag = false;
                    break;
                }
            }
            if(flag)
            {
                puts("aaaa");
            }
        }
    }
    return 0;
}
原文地址:https://www.cnblogs.com/jifahu/p/5450434.html