1260:找子串

来源:互联网 发布:mysql条件查询语句 编辑:程序博客网 时间:2024/06/08 18:46

1260:找子串


Description


给定原子串和目标子串,要求你求得目标子串在原子串当中出现的次数。


Input


多组测试数据,每组测试数据第一行是原子串,第二行是目标子串。

子串长度不会超过100。


Output


输出目标子串在原子串当中出现的次数。


Sample Input


abc123abc

abc

aabcCdeAbcdeccde

cde


Sample Output


2

2


Source


ipc4th@ahstu

#include<iostream>#include<string>using namespace std;int main(){    string a,b;    while(cin>>a>>b)    {    int length1=a.length();    int length2=b.length();    int i=0,j,count=0;   while(i<length1)   {        for(j=i;j<i+length2;j++)        {            if(a[j]!=b[j-i])                break;        }        if(j==i+length2)            count++;            i++;    }    cout<<count<<endl;     }    return 0;}



原创粉丝点击