UVALive - 4222
题目链接:https://vjudge.net/contest/244167#problem/D
题目:
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.
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 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
#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的更多相关文章
- UVALive 4222 Dance 模拟题
Dance 题目连接: https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&pag ...
- UVALive 4222 /HDU 2961 Dance 大模拟
Dance Problem Description For a dance to be proper in the Altered Culture of Machinema, it must abid ...
- UVALive - 4108 SKYLINE[线段树]
UVALive - 4108 SKYLINE Time Limit: 3000MS 64bit IO Format: %lld & %llu Submit Status uDebug ...
- UVALive - 3942 Remember the Word[树状数组]
UVALive - 3942 Remember the Word A potentiometer, or potmeter for short, is an electronic device wit ...
- UVALive - 3942 Remember the Word[Trie DP]
UVALive - 3942 Remember the Word Neal is very curious about combinatorial problems, and now here com ...
- 思维 UVALive 3708 Graveyard
题目传送门 /* 题意:本来有n个雕塑,等间距的分布在圆周上,现在多了m个雕塑,问一共要移动多少距离: 思维题:认为一个雕塑不动,视为坐标0,其他点向最近的点移动,四舍五入判断,比例最后乘会10000 ...
- UVALive 6145 Version Controlled IDE(可持久化treap、rope)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...
- UVALive 6508 Permutation Graphs
Permutation Graphs Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- UVALive 6500 Boxes
Boxes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pract ...
随机推荐
- css引入的两种方法link和@import的区别和用法
link和@import都是HTML中引入CSS的语法单词. 两者的基本语法 link语法结构 <link href="外部CSS文件的URL路径" rel="st ...
- 03 测试Hadoop hdfs 上传 与 mr
1.随便在哪个目录新增一个文档.内容随便输入 mkdir words 2.在hdfs 中新建文件输入目录 ./hdfs dfs -mkdir /test 3.把新建的文档 (/home/hadoop/ ...
- jQuery 事件 - triggerHandler() 方法
定义和用法 triggerHandler() 方法触发被选元素的指定事件类型.但不会执行浏览器默认动作,也不会产生事件冒泡. triggerHandler() 方法与 trigger() 方法类似.不 ...
- Eclipse中修改jsp、html……的编码格式
一般如果使用的是Eclipse的默认编码格式,在我们保存的时候会提示选择保存的编码格式,保存后英文没有问题,但是中文就会乱码. 修改方式是: Windows——>Preferences——> ...
- python设计模式第十七天【解释器模式】
1.应用场景 (1)解释预先定义的文法 2.代码实现 #!/usr/bin/env python #!_*_ coding:UTF-8 _*_ from abc import ABCMeta, abs ...
- shiro使用ajax登陆实现,success但页面无法跳转的问题
首先:简述一下登陆的后台流程 页面提交——>对应controller中的方法——>对应Realm认证——>controller返回 json 这样,无论成功与否,都有返回值,可以用 ...
- wget 下载网页
如有转载,不胜荣幸.http://www.cnblogs.com/aaron-agu/ wget --http-user=username --http-passwd=password http:/w ...
- 获取DataSet中某行某列的数据
LabelText = DataSet11.Tables("COMM.USERS").Rows[0]["User_Name"].tostring() Label ...
- 一、IntelliJ IDEA创建java项目
一.IntelliJ IDEA创建java项目 二.IntelliJ IDEA下载并包含jdbc包 1.下载zip格式的驱动包:https://dev.mysql.com/downloads/conn ...
- python 基础篇
1.编程语言介绍. 1.机器语言:直接用二进制编程,直接对硬件的控制,需对硬件掌握比较深. 优点:执行效率快 缺点:开发效率低下 2.汇编语言:用英文标签代替二进制编写程序,直接对硬件的控制,需对硬件 ...