zoukankan      html  css  js  c++  java
  • 【CF 138A】Literature Lesson(字符串处理+模拟)

    传送门:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=114353#problem/F

    第一次pc^2练习赛,队内大腿回家,没有比赛……比的艰辛无比。

    题意:每4句诗构成一组,分为4种韵律,aabb,aaaa,abab,abba。一首长诗如果每组都是一种韵律,那么整首诗的韵律就是这种,如果是由aaaa和其他韵律构成的,那么就是那种韵律,如果是由除了aaaa这种之外的两种或以上构成的,就输出NO。

    分析:最开始没太读懂题意,后来按照自己的理解试着敲一发,运气1A。这题就是把每组输入从后向前进行处理,处理到第k个元音,如果字符中元音大于k,则输出肯定为no,之后基本就是模拟比较的过程,容易错的地方主要是一共有几个需要特判,也就是需要标记最后统一输出no的,具体的代码中有。

    代码:

    /* ***********************************************
    Author        :Torrance_ZHANG
    Created Time  :2016/4/30 20:50:27
    File Name     :ceshi.cpp
    ************************************************ */
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    typedef long long int LL;
    using namespace std;
    char s[100010],ss[5][100010];
    int tmp[10];
    int main(){
        int n,k,l;
        while(~scanf("%d%d",&n,&k)){
            bool flag=true;
            memset(tmp,0,sizeof(tmp));
            for(int i=1; i<=n; i++){
                memset(ss,'',sizeof(ss));
                for(int j=1; j<=4; j++){
                    scanf("%s",s);
                    int pos=k;
                    int len=strlen(s);
                    for(l=len-1; l>=0&&pos>0; l--){
                        ss[j][len-l-1]=s[l];
                        if(s[l]=='a'||s[l]=='e'||s[l]=='i'||s[l]=='o'||s[l]=='u'){
                            pos--;
                        }
                    }
                    /*for(int ii=0;ii<len-l;ii++)
                        cout<<ss[j][ii]<<endl;*/
                    if(pos>0)
                        flag=false;
                }
                int f12=strcmp(ss[1],ss[2]);
                int f23=strcmp(ss[2],ss[3]);
                int f14=strcmp(ss[1],ss[4]);
                int f24=strcmp(ss[2],ss[4]);
                int f34=strcmp(ss[3],ss[4]);
                int f13=strcmp(ss[1],ss[3]);
                //cout<<f12<<" "<<f13<<" "<<f14<<" "<<f23<<" "<<f24<<" "<<f34<<endl;
                if(f12==0&&f34==0&&f13==0)
                    tmp[1]++;
                else if(f12==0&&f34==0&&f13!=0)
                    tmp[2]++;
                else if(f13==0&&f24==0&&f12!=0)
                    tmp[3]++;
                else if(f14==0&&f23==0&&f12!=0)
                    tmp[4]++;
                else flag=false;
                int ans=0;
                for(int i=2; i<=4; i++){
                    if(tmp[i]>0)
                        ans++;
                }
                if(ans>1)
                    flag=false;
            }
            if(!flag)
                printf("NO
    ");
            else{
                if(tmp[2]>0)
                    printf("aabb
    ");
                else if(tmp[3]>0)
                    printf("abab
    ");
                else if(tmp[4]>0)
                    printf("abba
    ");
                else printf("aaaa
    ");
            }
        }
    }
  • 相关阅读:
    Java 项目运用个人看法(简写)
    windows 搭建Solr连接数据库
    总结2016年,计划2017
    如何解决,自己认为特别难的问题?(文摘)
    spring -quartz 定时任务多任务配置
    (转) java Timer 定时每天凌晨1点执行任务
    spring多数据源切换,写入报错的问题
    如何合理和有效的进行数据库设计
    Main方法定点执行线程任务
    莫辜负当下,莫悔恨过去,莫打扰错过的人
  • 原文地址:https://www.cnblogs.com/Torrance/p/5449740.html
Copyright © 2011-2022 走看看