UVALive 4222 Dance 模拟题

本文介绍了一个自动检查器,用于验证舞蹈是否遵循特定的文化规则,包括步骤顺序、元素出现的位置等,确保舞蹈的正确性和合规性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Dance

题目连接:

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2223

Descriptionww.co

For a dance to be proper in the Altered Culture of Machinema, it must abide by the following rules:
A dip can only appear 1 or 2 steps after a jiggle, or before a twirl, as in:
...jiggle dip...
...jiggle stomp dip...
...dip twirl...
All dances end with a clap stomp clap.
If a dance contains a twirl, it must have a hop.
No dance can start with a jiggle.
All dances must have a dip.
As instructor at a dance composition school, you must grade many freshman attempts at composing dances. You decide to make an automatic grader that can check against these rules.

Input

The input consists of a number of dances, one per line. Each dance has a maximum of 1000 steps. Each step is separated by a single space, and all steps are lowercase alphabetic words at most 100 letters long.

Output

If a dance in the input has no mistakes, then the output should contain the words "form ok: " followed by the original composition.
If a dance has a single type of form error, then the output should contain the words "form error K: " where K is the rule which failed, followed by the composition.
If a dance has multiple types of form errors, then the output should contain the errors as a comma separated clause, as in "form errors K(1), K(2), ..., K(N-1) and K(N): " where the form errors are in increasing order, followed by the composition.
If a dance has form error 1, every dip in the dance that violates rule 1 should be printed in upper case.

Sample Input

dip twirl hop jiggle hop hop clap stomp clap
dip hop jiggle hop hop clap stomp clap
dip twirl hop jiggle hop hop clap clap stomp
jiggle dip twirl hop jiggle hop hop clap stomp clap
jiggle dip
jiggle
dip twirl hop dip jiggle hop dip hop clap stomp clap

Sample Output

form ok: dip twirl hop jiggle hop hop clap stomp clap
form error 1: DIP hop jiggle hop hop clap stomp clap
form error 2: dip twirl hop jiggle hop hop clap clap stomp
form error 4: jiggle dip twirl hop jiggle hop hop clap stomp clap
form errors 2 and 4: jiggle dip
form errors 2, 4 and 5: jiggle
form error 1: dip twirl hop DIP jiggle hop dip hop clap stomp clap

Hint

题意

给你一个句子,判断这个句子有没有犯错,犯了哪些错

规则如下:

A dip can only appear 1 or 2 steps after a jiggle, or before a twirl, as in:
...jiggle dip...
...jiggle stomp dip...
...dip twirl...
All dances end with a clap stomp clap.
If a dance contains a twirl, it must have a hop.
No dance can start with a jiggle.
All dances must have a dip.

题解:

模拟题,没有任何坑点,除了输出比较蛋疼外

模拟一遍就好了

代码

#include<bits/stdc++.h>
using namespace std;

string str;
int tot = 0;
string s[3000];
void slipe()
{
    tot = 0;
    for(int i=0;i<str.size();i++)
    {
        if(str[i]==' ')
        {
            tot++;
            continue;
        }
        s[tot]+=str[i];
    }
    tot++;
}
int vis[3000];
int flag[10];
int main()
{
    while(getline(cin,str))
    {
        memset(flag,0,sizeof(flag));
        memset(vis,0,sizeof(vis));
        for(int i=0;i<3000;i++)
            s[i]="";
        slipe();
        for(int i=0;i<tot;i++)
        {
            if(s[i]=="dip")
            {
                vis[i]=1;
                if(s[i+1]=="twirl")
                {
                    vis[i]=0;
                }
                else
                {
                    if(i>0&&s[i-1]=="jiggle")
                    {
                        vis[i]=0;
                    }
                    else
                    {
                        if(i>1&&s[i-2]=="jiggle")
                        {
                            vis[i]=0;
                        }
                    }
                }
            }
        }
        for(int i=0;i<tot;i++)
            if(vis[i])flag[1]=1;
        if(tot<3)
            flag[2]=1;
        else
        {
            if(s[tot-1]!="clap"||s[tot-2]!="stomp"||s[tot-3]!="clap")
                flag[2]=1;
        }
        for(int i=0;i<tot;i++)
            if(s[i]=="twirl")
                flag[3]=1;
        if(flag[3])
        {
            for(int i=0;i<tot;i++)
                if(s[i]=="hop")
                    flag[3]=0;
        }
        if(s[0]=="jiggle")
            flag[4]=1;
        flag[5]=1;
        for(int i=0;i<tot;i++)
            if(s[i]=="dip")
                flag[5]=0;

        int num = 0;
        for(int i=1;i<=5;i++)
            if(flag[i])num++;
        if(num==0)
        {
            printf("form ok: ");
            cout<<str<<endl;
        }
        else if(num==1)
        {
            for(int i=1;i<=5;i++)
                if(flag[i])num=i;
            printf("form error %d:",num);
            for(int i=0;i<tot;i++)
            {
                if(vis[i])cout<<" DIP";
                else cout<<" "<<s[i];
            }
            cout<<endl;
        }
        else
        {
            for(int i=1;i<=5;i++)
                if(flag[i])num=i;
            printf("form errors ");
            int first = 1;
            for(int i=1;i<=5;i++)
            {
                if(!flag[i])continue;
                if(num==i)
                {
                    printf(" and %d:",num);
                    continue;
                }
                if(first)
                {
                    cout<<i;
                    first=0;
                }
                else
                {
                    cout<<", "<<i;
                }
            }
            for(int i=0;i<tot;i++)
            {
                if(vis[i])cout<<" DIP";
                else cout<<" "<<s[i];
            }
            cout<<endl;
        }
    }
}

转载于:https://www.cnblogs.com/qscqesze/p/5152373.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值