子串

#include<stdio.h>
#include<string.h>
int main()
{
    int n,i,k,a,b,x,j;
    char st1[1000003],st2[7];
    scanf("%d%*c",&n);
    while(n--)
    {
        x=0;
        scanf("%s %s",st1,st2);
        a=strlen(st1);
        b=strlen(st2);
        for(i=0;i<a;)
        {
            k=0;
            for(j=0;j<b;j++)
            {
                if(st1[i+j]!=st2[j])
                    k++;
            }
            if(k==0)
            {
                x++;i=i+b;
            }
            else i++;
        }
        printf("%d\n",x);
    }
    return 0;
}
		
 
 
Problem Description
Some dangerous Witches invaded the garden city! As a righteous magician, james0zan want to find the most powerful incantation so he can beat those dangerous witches easily.
After consulted one hundred and eight thousand Magic Books, james0zan find a way to calculate the power of an incantation. There is a very short incantation called “magic index” which contains the magic power, and each incantation’s power can be calculated by the times the “magic index” appearance in the incantation. Notice that if two “magic index” overlapped, the power only should be calculated once. And we just want the incantation more powerful. That is to say, if the “magic index” is “aa”, the power of incantation “aaaa” is 2(“aa”+”aa”), not 1(“a”+”aa”+”a”) or 3.
 
Input
The first line is an integer t (t<=30), the number of test cases. Each of the next t lines contains two strings, represent the incantation (length<=10^6) and the “magic index” (length<=5). Every char in the incantation and the magic index is lowercase.
 
Output
For each test case you should output the power of the incantation.
 
SampleInput
3
aaaa aa
bsdjfassdiifo sd
papapapapapapap ap
 
SampleOutput
2
2
7
 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值