HDU 2203 strstr()函数应用

来源:互联网 发布:金融期货交易软件 编辑:程序博客网 时间:2024/06/06 10:52

http://acm.hdu.edu.cn/showproblem.php?pid=2203

/*

char* strstr(const char* a,constchar* b)  在a中寻找第一次出现b的位置

如果出现,返回位置,如果不出现,返回空指针;

利用这一特点,我们将s1字符串长度加长一部分(s2的长度),加长的内容为s1的前strlen(s2)个字符;

最后用函数判断s2是否在s1中出现;

over~~

*/


#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>#include <string>#include <iomanip>#define maxn 100005using namespace std;char s1[2*maxn],s2[maxn];int main(int argc, char *argv[]){while(scanf("%s%s",&s1,&s2)!=EOF){int len1 = strlen(s1),len2 = strlen(s2);if(len2>len1){puts("no");continue;}for(int i = len1,j = 0; i < len1+len2; i++){s1[i] = s1[j++];}len1 = len1+len2;if(strstr(s1,s2)!=NULL){puts("yes");}else{puts("no");}}return 0;}