UVALive 4222 /HDU 2961 Dance 大模拟
Dance
Problem Description
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.
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.
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
题意:
给出一串 dance串
问你是否满足 5个要求,不满足 输出哪些,对于要求1不满足 的dip都改成大写
需要满足条件如下:
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.
* ...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.
题解:
死模拟题
#include <iostream> #include <cstdio> #include <cmath> #include <cstring> #include <algorithm> #include<vector> using namespace std ; typedef long long ll; const int N = 2000000 + 10; const int inf = 1e9 + 7; char a[N]; int len,H[N]; int check4() { if(len < 6) return 1; char b[10] = {'j','i','g','g','l','e'}; int cnt = 0; for(int i = 0; i < 6; i++) { if(a[i] != b[cnt]) return 1; cnt++; } return 0; } int check2() { if(len < 15) return 0; char b[30] = {"clap stomp clap"}; int cnt =0 ; for(int i = len - 15; i < len ;i ++) { if(a[i]!=b[cnt++]) return 0; } return 1; } int check5() { for(int i = 0; i < len - 2; i+=1) { if(a[i] == 'd' && a[i+1] == 'i' && a[i+2] == 'p') return 1; } return 0; } int check3() { if(len < 5) return 1; for(int i = 0; i <= len - 5; i++) { if(a[i] == 't' && a[i+1] == 'w' && a[i+2] == 'i' && a[i + 3] == 'r'&&a[i+4]=='l') { for(int i = 0; i < len - 2; i++) { if(a[i] == 'h' && a[i+1] == 'o' && a[i+2] == 'p') return 1; } return 0; } } return 1; } void solve() { memset(H,0,sizeof(H)); vector<int> ans; len = strlen(a); if(!check2()) H[2] = 1; if(!check3()) H[3] = 1; if(!check4()) H[4] = 1; if( check5() ) { for(int i = 0; i < len - 2; i++) { if(a[i] == 'd' && a[i+1] == 'i' && a[i+2] == 'p') { int f = 1; if(i - 7 >= 0) { int cnt2= 0; for(int j = i - 1; j >= 0 ; j--) { if(a[j] ==' ') cnt2++; if(cnt2 == 2) {cnt2 = j;break;} } if(cnt2 - 6 >= 0) { int flag = 0; char b[20] = {"jiggle"};int cnt = 0; for(int j = cnt2 - 6; j < cnt2; j ++) { if(a[j]!= b[cnt++]) {flag =1;break;} } if(!flag) f = 0; } } if(i - 7 >= 0) { int flag = 0; char b[20] = {"jiggle "};int cnt = 0; for(int j = i - 7; j < i; j ++) { if(a[j]!= b[cnt++]) {flag =1;break;} } if(!flag) f = 0; } if(i + 8 < len) { int flag = 0; char b[20] = {" twirl"};int cnt = 0; for(int j = i + 3; j <= i+8; j ++) { if(a[j]!= b[cnt++]) {flag =1;break;} } if(!flag) f = 0; } if(f) { a[i] = 'D'; a[i+1] = 'I'; a[i+2] = 'P'; H[1] = 1; } i += 2; } } } else H[5] = 1; for(int i = 1; i <= 5; i++) { if(H[i]) ans.push_back(i); } if(!ans.size())cout<<"form ok: "<<a<<endl; else if(ans.size()==1) printf("form error %d: %s\n",ans[0],a); else if(ans.size() == 2) printf("form errors %d and %d: %s\n",ans[0],ans[1],a); else if(ans.size() == 3) printf("form errors %d, %d and %d: %s\n",ans[0],ans[1],ans[2],a); else if(ans.size() == 4) printf("form errors %d, %d, %d and %d: %s\n",ans[0],ans[1],ans[2],ans[3],a); else if(ans.size() == 5) printf("form errors %d, %d, %d, %d and %d: %s\n",ans[0],ans[1],ans[2],ans[3],ans[4],a); } int main() { while(gets(a)!=NULL) { solve(); } return 0; }