https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2223
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.
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.
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.
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
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
给你一个句子,判断这个句子有没有犯错,犯了哪些错
规则如下:
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;
}
}
}