Gym 101028F-Good Words
来源:互联网 发布:ow网络初始化失败 编辑:程序博客网 时间:2024/05/22 03:32
题目描述:
Zaid has two words, a of length between 4 and 1000 andb of length 4 exactly. The word a is 'good' if it has a substring which is equal to b. However, a is 'almost good' if by inserting a single letter inside of it, it would become 'good'. For example, ifa = 'start' and b = 'tear':b is not found inside of a, so it is not 'good', but if we inserted the letter 'e' inside ofa, it will become 'good' ('steart'), so a is 'almost good' in this case. Your task is to determine whether the worda is 'good' or 'almost good' or neither.
Input
The input consists of several test cases. The first line of the input contains a single integerT, the number of the test cases. Each of the followingT lines represents a test case and contains two space separated stringsa and b, each of them consists of lower case English letters. It is guaranteed that the length ofa is between 4 and 1000, and the length ofb is exactly 4.
Output
For each test case, you should output one line: if a is 'good' print 'good', ifa is 'almost good' print 'almost good', otherwise print 'none'.
Sample Input
4smart markstart tearabracadabra crabtestyourcode your
almost goodalmost goodnonegood代码实现:
#include<iostream>#include<cstring>using namespace std;int main(){ int t,la,f,i,j; char a[1100],b[1100],c[4][1100]; cin>>t; while(t--) { cin>>a>>b; la=strlen(a); for(i=1; i<4; i++) { c[0][i-1]=b[i]; } c[0][3]=NULL; c[1][0]=b[0]; c[1][1]=b[2]; c[1][2]=b[3]; c[1][3]=NULL; c[2][0]=b[0]; c[2][1]=b[1]; c[2][2]=b[3]; c[2][3]=NULL; c[3][0]=b[0]; c[3][1]=b[1]; c[3][2]=b[2]; c[3][3]=NULL;// cout<<a<<endl<<b<<endl;// for(i=0;i<4;i++)// {// cout<<c[i]<<endl;// } f=0; for(i=0; i<la; i++) { if(a[i]==b[0]&&a[i+1]==b[1]&&a[i+2]==b[2]&&a[i+3]==b[3]) { cout<<"good"<<endl; f=1; break; } } if(f==0) { for(i=0; i<la; i++) { if(a[i]==c[2][0]&&a[i+1]==c[2][1]&&a[i+2]==c[2][2]) { cout<<"almost good"<<endl; f=1; break; } } } if(f==0) { for(i=0; i<la; i++) { if(a[i]==c[0][0]&&a[i+1]==c[0][1]&&a[i+2]==c[0][2]) { cout<<"almost good"<<endl; f=1; break; } } } if(f==0) { for(i=0; i<la; i++) { if(a[i]==c[1][0]&&a[i+1]==c[1][1]&&a[i+2]==c[1][2]) { cout<<"almost good"<<endl; f=1; break; } } } if(f==0) { for(i=0; i<la; i++) { if(a[i]==c[2][0]&&a[i+1]==c[2][1]&&a[i+2]==c[2][2]) { cout<<"almost good"<<endl; f=1; break; } } } if(f==0) { for(i=0; i<la; i++) { if(a[i]==c[3][0]&&a[i+1]==c[3][1]&&a[i+2]==c[3][2]) { cout<<"almost good"<<endl; f=1; break; } } }// if(f==0)// {// for(i=0; i<la-3; i++)// {// for(j=0; j<4; j++)// {// if(a[i]==c[j][0]&&a[i+1]==c[j][1]&&a[i+2]==c[j][2])// {// cout<<"almost good"<<endl;// f=1;// break;// }// }// if(f==1)// {// break;// }// }// } if(f==0) { cout<<"none"<<endl; } } return 0;}错误代码:
#include<iostream>#include<cstring>using namespace std;int main(){ int t,la,f,i,j; char a[1100],b[1100],c[4][1100]; cin>>t; while(t--) { cin>>a>>b; la=strlen(a); for(i=1;i<4;i++) { c[0][i-1]=b[i]; } c[0][3]=NULL; c[1][0]=b[0]; c[1][1]=b[2]; c[1][2]=b[3]; c[1][3]=NULL; c[2][0]=b[0]; c[2][1]=b[1]; c[2][2]=b[3]; c[2][3]=NULL; c[3][0]=b[0]; c[3][1]=b[1]; c[3][2]=b[2]; c[3][3]=NULL;// cout<<a<<endl<<b<<endl;// for(i=0;i<4;i++)// {// cout<<c[i]<<endl;// } f=0; for(i=0;i<la-3;i++) { //cout<<1; if(a[i]==b[0]&&a[i+1]==b[1]&&a[i+2]==b[2]&&a[i+3]==b[3]) { cout<<"good"<<endl; f=1; break; } for(j=0;j<4;j++) { if(a[i]==c[j][0]&&a[i+1]==c[j][1]&&a[i+2]==c[j][2]) { cout<<"almost good"<<endl; f=1; break; } } if(f==1) { break; } } if(f==0) { cout<<"none"<<endl; } } return 0;}如果a:mardsmark b:mark
那么错误代码的输出结果:almost good,原因是从字符串的第一个字符开始遍历,如果遇到almost good的情况就会停止遍历,而不管后面时候会有good的情况
- Gym 101028F-Good Words
- Good Words Gym-101028F
- Gym 100703F Game of words 动态规划
- good words
- [Gym-101350F] F
- Gym 100685 F Flood
- Gym 100989F STL
- codeforces Gym 101102F
- Codeforces-GYM-100726F
- Codeforces GYM 100803F
- Gym - 100947F
- [Gym-100520F]
- Gym 101142F Folding
- Gym 100553F-Filter
- Gym 101164.F
- Gym 101482.F
- Gym 101201.F
- Gym 100513F - Ilya Muromets
- 在leangoo里怎么复制卡片,删除卡片,查看任务轨迹?
- linux脚本实现监控某个进程并重启
- swift去除掉指定分割线
- Bean和Map相互转化-Java工具类(一)
- 自学swift (1)
- Gym 101028F-Good Words
- 开机启动ftp服务
- C 语言笔记;变量初始化
- 七牛qiniu c/c++ sdk 在windows系统环境下使用vs导入lib静态库的使用教程总结
- STM32F1之定时器
- Python2.7 urlparse学习
- 基于express的精简web服务
- Saving HDU
- 常用js语法小记