花露水和暖壶


私信TA

用户名:MichaelMeng

访问量:8666

签 名:

等  级
排  名 82
经  验 9157
参赛次数 0
文章发表 28
年  龄 0
在职情况 学生
学  校 烟台大学
专  业

  自我简介:

不喜欢摇滚乐的研究生不是好程序猿!

    大家可以趁着这道题复习一波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 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区