sse——字符串数组

//练习题2. 字符串数组
//输入两个长度小于100的字符串A和B,且A的长度大于B的长度,判断B是不是A的子串,是则输出”YES”,否则输出”NO”。注意:串中任意个连续的字符组成的子序列称为该串的子串。
//提示:不需要使用自定义函数实现,也不能使用已有的字符串查找子串函数
//输入:输入两行,第一行为字符串A,第二行为字符串B。
//输入提示信息:"Please input the first str:"
//输入格式:"%s"
//输入提示信息:"Please input the second str:"
//输入格式:"%s"
//如:
//Please input the first str: Abcdefghijk123
//Please input the second str: 123
//或
//Please input the first str: abefsfl
//Please input the second str: befs
//或
//Please input the first str: aAbde
//Please input the second str: abc
//输出:按题目要求输出一行,"YES" 或 "NO"。
//输出样例:
//YES
//或
//YES
//或
//NO
#include<stdio.h>
#include<string.h>
#define maxLen 100 //0.5
int main()
{                   
    char a[maxLen];
    char b[maxLen];
    printf("Please input the first str:");
    scanf("%s", a);
    getchar();
    printf("Please input the second str:");
    scanf("%s", b);
    int i = 0, j = 0;
    int ans = 0;
    while (i < strlen(a) - strlen(b) + 1)//1
    {                   
        if (j == strlen(b))
        {                   
            ans = 1;
            break;
        }
        if (a[i + j] == b[j])//1
            ++j;//1
        else
        {                   
            j = 0;
            ++i;//1
        }
    }
    if (ans)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}         

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值