大家可以趁着这道题复习一波C语言中关于str的相关函数。确实省了不少事
参考代码:
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h> int main() { char s1[100000] = {'\0'}, s2[100000] = {'\0'}; while (scanf("%s%s", s1, s2) != EOF) { char str[100000] = {'\0'};//开辟一个新字符串数组 //把s1复制2份放进str中,例如s1="ABC",则操作结束后str="ABCABC" strcat(str, s1);//srtcat(s1,s2)的作用是在s1后面追加s2 strcat(str, s1); //strstr(s1, s2)返回s2在s1中出现的位置,找到则返回位置,找不到则返回NULL if (strstr(str, s2) != NULL) { printf("yes\n"); } else { printf("no\n"); } } return 0; }
0.0分
2 人评分