亲和串
来源:互联网 发布:淘宝旗舰店如何开 编辑:程序博客网 时间:2024/06/05 19:37
G - 亲和串
Crawling in process... Crawling failed Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit Status
Description
人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题。
亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。
Input
本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二行包含输入字符串s2,s1与s2的长度均小于100000。
Output
如果s2是s1的亲和串,则输出"yes",反之,输出"no"。每组测试的输出占一行。
Sample Input
AABCD
CDAA
ASD
ASDF
Sample Output
yes
no
*/
// 库函数算法*****
//#include <cmath>//#include <ctime>//#include <deque>//#include <queue>//#include <stack>//#include <cctype>//#include <sstream>//#include <vector>//#include <cassert>//#include <cstdlib>//#include <algorithm>//#include <cstdio>//#include <cstring>#include <string>#include <iostream>using namespace std;int main(){// freopen("in.txt","r",stdin); char a[100001],b[100001],c[200002]; while(gets(a)) { gets(b); strcpy(c,a); strcat(c,a); if(strstr(c,b)!=NULL && strlen(a)>=strlen(b)) cout<<"yes"<<endl; else cout<<"no"<<endl; } return 0;}
点击打开链接http://acm.hdu.edu.cn/showproblem.php?pid=2203/*
// KMP算法*******
/
#include <iostream>#include <string>#include <string.h>#include <cstdio>using namespace std;const int N=100010;int nextt[N],len1,len2,len;char s[N],ss[N],str[2*N];void getnext(){ nextt[1]=0; int i=1,j=0; while(i<=len2){ if(j==0||ss[i]==ss[j]){ ++i;++j;if(ss[i]!=ss[j])nextt[i]=j;elsenextt[i]=nextt[j]; } else j=nextt[j]; }}int kmp(){ int i=1,j=1; while(i<=len&&j<=len2){ if(j==0||str[i]==ss[j]){ ++i;++j; } else j=nextt[j]; } if(j>len2) return i-len2; return 0;}int main(){ while(scanf("%s%s",s+1,ss+1)!=EOF){ memset(nextt,0,sizeof(nextt)); len1=strlen(s+1); len2=strlen(ss+1); if(len1<len2) {printf("no\n");continue;}for(int i=1;i<=len1;++i)str[i]=s[i];len=len1;for(int i=1;i<=len1;++i)str[++len]=s[i];getnext();int flag=kmp();if(flag==0)printf("no\n");elseprintf("yes\n"); } return 0;}
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- 亲和串
- hud_ACM_2203_亲和串
- HDU 2203 亲和串
- hdu2203 亲和串
- HDU 2203 亲和串
- HDU - 2203 亲和串
- hdu 2203 亲和串
- HDU2203:亲和串
- Boost Thread学习
- linux 重启命令
- 【Silverlight】Bing Maps开发应用与技巧一:地图打点与坐标控件(CoordControl)
- 《计算机教育》专题报道:“米老师”其人
- extjs使利用cookie换皮肤,华丽转身!
- 亲和串
- 总结两种创建匿名管道来截获控制台命令的方法
- jdbc 可更新结果集
- 在ASP.NET中实现ajax
- 继扎扎之后 苹果CEO入驻图片社交网站The Fancy
- hibernate学习
- const和static区别
- httpclient4 中文版帮助文档,最新官方版翻译版(一)
- 暑假个人赛3 A题