题目链接https://vjudge.net/contest/244167#problem/D

题目:

For a dance to be proper in the Altered Culture of Machinema, it must abide by the following rules:
1 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...
2 All dances end with a clap stomp clap.
3 If a dance contains a twirl, it must have a hop.
4 No dance can start with a jiggle.
5 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
 
题目大意:给你一行跳舞的字符串,由不超过1000个单词组成(仅包含单词和空格),每个单词不超过100个字母,需要满足一下5个要求:
1.“dip”一定要在“jiggle”后面一个单词或两个单词,或者在twirl前面一个单词,其他都是错的。
2.每个字符串的一定要以“clap stomp clap”结尾,否则就是错的。
3.如果该行字符串包含“twirl”,就一定要有“hop”,否则就是错的。
4.该行字符串不能以“jiggle”开头。
5.该行字符串一定要有“dip”。
判断该行字符串是否有错,如果没错就直接输出 ‘form ok:’加上输入的那行字符串,如果有错,就输出那么错误的编号,再加上输入的那行字符串,注意,如果是错误1的话,需要将错误的dip改成大写的DIP,具体输出格式看样例。
 
解题思路:这题目有点水,当时比赛时看起来好像挺麻烦的就没去做,其实那几个条件判断都不是很复杂。也不用想啥思路的,直接就是输入后一个一个条件判断就是了。输入一行可以用getline()输入,然后将每个单词分开就行。条件判断有点复杂的就是条件1吧,开始都判断错了,可以直接判断符合该条件的所有情况,反过来就是不符合该条件的情况。然后这个题目最变态的就是这输出格式了,弄的那么复杂,还是要挺小心的。代码有点长,码力还比较弱,码了挺久的,开始样例都没过,改错改来改去的,还好一次提交就过了。。
 
附上代码:
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
string str;
int flag[]; int main()
{
while(getline(cin,str))
{
vector<string> vec;
memset(flag,,sizeof(flag));
for(int i=;i<;i++)
vec.clear();
int len=str.length();
string ss;
for(int i=;i<len;i++)
{
if(str[i]!=' ')
{
ss+=str[i];
}
if(str[i]==' '||i==len-)
{
vec.push_back(ss);
ss="";
}
}
//判断条件2
if(str.size()<)
flag[]=;
else
{
string sss=str.substr(str.size()-,);
//cout<<sss<<endl;
if(sss!="clap stomp clap")
flag[]=;
}
//cout<<flag[2]<<endl;
str.clear();
int l=vec.size(),cntdip=,cnthop=,cnttwirl=;
for(int i=;i<l;i++)
{
//cout<<vec[i]<<endl;
if(vec[]=="jiggle") //判断条件4
{
flag[]=;
}
if(vec[i]=="twirl")
cnttwirl++;
if(vec[i]=="hop")
cnthop++;
if(vec[i]=="dip") //判断条件1
{
cntdip++;
int flag1=,flag2=,flag3=;
if(i>=&&vec[i-]=="jiggle")
flag1=;
if(i>=&&vec[i-]=="jiggle")
flag2=;
if(i<=l-&&vec[i+]=="twirl")
flag3=;
if(flag1==&&flag2==&&flag3==) //全都不符合说明是错的
{
flag[]=;
vec[i]="DIP";
}
}
}
if(cnttwirl!=&&cnthop==) //判断条件3
flag[]=;
if(cntdip==) //判断条件5
flag[]=;
int cnt=,k;
for(int i=;i<=;i++)
{
if(flag[i])
{
cnt++;
k=i;
}
}
if(cnt==)
cout<<"form ok: ";
else if(cnt==)
printf("form error %d: ",k);
else
{
int k=;
printf("form errors ");
for(int i=;i<=;i++)
{
if(flag[i])
{
k++;
if(k==cnt-)
printf("%d and ",i);
else if(k==cnt)
printf("%d: ",i);
else
{
printf("%d, ",i);
}
}
}
}
for(int i=;i<l;i++)
{
if(i==)
cout<<vec[i];
else
cout<<" "<<vec[i];
}
cout<<endl;
}
return ;
}
 

UVALive - 4222的更多相关文章

  1. UVALive 4222 Dance 模拟题

    Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...

  2. UVALive 4222 /HDU 2961 Dance 大模拟

    Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...

  3. UVALive - 4108 SKYLINE[线段树]

    UVALive - 4108 SKYLINE Time Limit: 3000MS     64bit IO Format: %lld & %llu Submit Status uDebug ...

  4. UVALive - 3942 Remember the Word[树状数组]

    UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...

  5. UVALive - 3942 Remember the Word[Trie DP]

    UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...

  6. 思维 UVALive 3708 Graveyard

    题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...

  7. UVALive 6145 Version Controlled IDE(可持久化treap、rope)

    题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...

  8. UVALive 6508 Permutation Graphs

    Permutation Graphs Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  9. UVALive 6500 Boxes

    Boxes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pract ...

随机推荐

  1. asp.net core前后端分离

    陆陆续续的看了两个礼拜的前端知识,把vue+vue-router+axios的知识撸了一遍,本来想加个element-ui来实现一下前后端分离,实施的时候却遇到了很多的坑.我本身不在一个软件开发公司上 ...

  2. Git-用 cherry-pick 挑好看的小樱桃

         版权声明:本文为博主原创文章,转载请在文章明显位置标明文章原属哦. https://blog.csdn.net/qq_32452623/article/details/79449534 ti ...

  3. 20181114教学sql

    --精确查找:查询水表编号为30408的业主记录 ' --模糊查询:查询业主名称包含'刘'的业主记录 SELECT * FROM T_OWNERS WHERE NAME LIKE '%刘%' --AN ...

  4. Eclipse打开java文件繁体字

    右键-->properties-->Resource-->Text file encoding, 改成utf-8 .

  5. python中的__init__和__new__的区别

    一.__init__ 方法是什么?(init前后的线是双下划线) 使用Python写过面向对象的代码的同学,可能对 __init__ 方法已经非常熟悉了,__init__ 方法通常用在初始化一个类实例 ...

  6. 如何在DataTemplate中绑定RadioButton的Checked事件

    在我们的项目中经常要用到数据模板,最近做的一个项目中在数据模板中要放一些RadioButton,其中每一个RadioButton设置了Checked事件,如果直接在View层写Checked事件的话不 ...

  7. 使用ultraiso制作启动盘安装windows操作系统

    1. 使用ultraiso制作u盘启动盘 在电脑上安装ultraiso: 启动ultraiso,文件->打开->选中iso镜像文件 菜单栏->启动->写入硬盘映像 a. 便捷启 ...

  8. pip install MySQL-python 失败

    1. EnvironmentError: mysql_config not found原因:/usr/bin/mysql_config没有次文件,要安装libmysqlclient-dev, apt ...

  9. adoquery怎样判断数据在缓存中有修改啊

    ADOQry.Filtered:=false;       ADOQry.Filtered:=true;       ADOQry.FilterGroup:=fgPendingRecords ;Fil ...

  10. Missing artifact com.oracle:ojdbc6:jar:11.2.0.3 Maven中不能引入ojdbc解决方法,错误

    今天从服务器检出Maven项目的时候,遇到了一个问题,就是在pom.xml中引入ojdbc的jar包的时候出错了,提示是Missing artifact com.oracle:ojdbc6:jar:1 ...