17.04.29 Powerful Incantation

Powerful Incantation

  HDU - 4150 

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.


Sample Input

3
aaaa aa
bsdjfassdiifo sd
papapapapapapap ap


Sample Output

2
2
7




可以说是非常水了。读个字符串,然后再读要查找的串,选0到strlen-1为起始点,再在内层循环逐个比较字符,这里如果有一个字符不一样就break,记有几个字符一样,如果和查找串的长度一样把外层循环的计数器放在当前找到的串的最后一位(因为不能重叠)。一遍过没什么好说。


#include<stdio.h>
#include<string.h>
int main()
{
    int t;
    scanf("%d\n",&t);

        while(t--)
        {
            char ss[1000002],sss[6];
            scanf("%s %s",ss,sss);
            //printf("%c %c\n",ss[3],sss[1]);
            int i,summ=0;
            for(i=0;i<=strlen(ss)-1;i++)
            {
                int j,sum=0;
                for(j=0;j<=strlen(sss)-1;j++)
                {
                    if(ss[i+j]==sss[j])sum++;
                    else break;
                }
                if(sum==strlen(sss))
                {
                    i=i+j-1;
                    summ++;
                }
            }
            printf("%d\n",summ);
        }

    return 0;
}





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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值