小编sha*_*nan的帖子

旋转的弦乐

编写代码来检查,如果s2是旋转s1仅使用一个调用isSubString(即waterbottle是一个旋转erbottlewat).

我为此编写程序,但我无法获得所需的输出.请指导我哪里出错了.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int isRotated(char *s1, char *s2);
int isSubstring(char *s1, char *s2);

int isRotated(char *s1, char *s2)
{
        int r;
        char s[100];
        if(strlen(s1) == strlen(s2))
                strcpy(s, s1);
        r = isSubstring(s, s2);
        strcat(s, s1);
        return r;
}

int isSubstring(char *s1, char *s2){
        if(strstr(s1, s2))
                return 1;   
        else    
                return 0;
}

int main(void) {
        char s1[100], s2[100];
        printf("Enter the first String\n");
        scanf("%s", s1);
        printf("Enter the second …
Run Code Online (Sandbox Code Playgroud)

c string substring

3
推荐指数
1
解决办法
191
查看次数

标签 统计

c ×1

string ×1

substring ×1