HDU【2203】亲和串
来源:互联网 发布:尚趣玩网络武神赵子龙 编辑:程序博客网 时间:2024/06/01 12:54
亲和串
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10739 Accepted Submission(s): 4886
Problem Description
人随着岁数的增长是越大越聪明还是越大越笨,这是一个值得全世界科学家思考的问题,同样的问题Eddy也一直在思考,因为他在很小的时候就知道亲和串如何判断了,但是发现,现在长大了却不知道怎么去判断亲和串了,于是他只好又再一次来请教聪明且乐于助人的你来解决这个问题。
亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。
亲和串的定义是这样的:给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。
Input
本题有多组测试数据,每组数据的第一行包含输入字符串s1,第二行包含输入字符串s2,s1与s2的长度均小于100000。
Output
如果s2是s1的亲和串,则输出"yes",反之,输出"no"。每组测试的输出占一行。
Sample Input
AABCDCDAAASDASDF
Sample Output
yesno#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int maxn = 100000 + 5;char T[maxn],P[maxn];int f[maxn];void Getf(char *P,int *f){ int len = strlen(P); f[0] = 0;f[1] = 0; for(int i = 1;i < len;i++) { int j = f[i]; while(j && P[i]!=P[j]) j = f[j]; f[i+1] =(P[i] == P[j]? j+1 : 0); }}int main(){ int i,j; while(scanf("%s%s",T,P)!=EOF) { int n = strlen(T); int m = strlen(P); Getf(P,f); j = 0; int flag = 0; for(i = 0 ; i < 2*n; i++) { while(j && T[i%n] != P[j]) j = f[j]; if(T[i%n] == P[j]) j++; if(j == m) { flag = 1; break; } } if(flag) cout << "yes" << endl; else cout << "no" << endl; } return 0;}
0 0
- HDU 2203 亲和串
- HDU 2203 亲和串
- HDU - 2203 亲和串
- hdu 2203 亲和串
- hdu 2203 亲和串
- HDU 2203 亲和串
- HDU-亲和串-2203
- hdu 2203 亲和串
- hdu 2203 亲和串
- hdu 2203 亲和串
- hdu 2203 亲和串
- HDU 2203 亲和串
- HDU 2203【亲和串】
- hdu 2203 亲和串
- HDU 2203 亲和串
- hdu 2203亲和串
- HDU 2203 亲和串
- HDU - 2203 亲和串
- JUI 添加或修改后不自动刷新是怎么回事?
- Error -27727: Step download timeout (120 seconds) has expired when downloading resource(s).
- oracle函数trunc的使用
- 关于Spring与mybatis整合无法读取配置文件的问题
- 用Node.js操作Firebird数据库。
- HDU【2203】亲和串
- cmake:在各级子项目(目录)之间共享变量
- 机器学习
- initMouseEvent
- NetworkingTool
- android 快速开发不可或缺的12个工具类
- Machine Learning结课感想
- wireshark mac版 interface网卡列表为空
- Java——刷题,考点,难点,查漏补缺