time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it’s new tablet Lastus 3000.

This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol’s artificial intelligence.

Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol’s director decided to replace some characters in AI name with “#”. As this operation is pretty expensive, you should find the minimum number of characters to replace with “#”, such that the name of AI doesn’t contain the name of the phone as a substring.

Substring is a continuous subsequence of a string.

Input

The first line of the input contains the name of AI designed by Gogol, its length doesn’t exceed 100 000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn’t exceed 30. Both string are non-empty and consist of only small English letters.

Output

Print the minimum number of characters that must be replaced with “#” in order to obtain that the name of the phone doesn’t occur in the name of AI as a substring.

Examples

input

intellect

tell

output

1

input

google

apple

output

0

input

sirisiri

sir

output

2

Note

In the first sample AI’s name may be replaced with “int#llect”.

In the second sample Gogol can just keep things as they are.

In the third sample one of the new possible names of AI may be “s#ris#ri”.

【题目链接】: http://codeforces.com/contest/625/problem/B

【题解】



乍看以为是一道kmp题。

但其实第二个串长度为30,第一个串长度为1e5;

复杂度用O(n*m)的枚举完全可以做;

贪心的话就是顺序枚举起始点i,对于i-j如果a[i..j] == b[0..lenb-1];那么就把a[j]改为井号就可以了。

然后就直接让i变成j+1开始再枚举起点.

感觉挺自然的一个贪心.



【完整代码】

/*
如果b的长度大于a的长度,直接输出0;
*/
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; //const int MAXN = x;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0); string a,b; int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> a >> b;
int lena = a.size(),lenb = b.size();
LL ans = 0;
rep1(i,0,lena-1)
{
int j = 0;
if (a[i]==b[j])
{
int ti = i;
while (ti<=lena-1 && j<=lenb-1 && a[ti]==b[j]) ti++,j++;
if (j==lenb)
{
ans++;
i = i+lenb-1;
}
}
}
cout << ans << endl;
return 0;
}

【38.02%】【codeforces 625B】War of the Corporations的更多相关文章

  1. 【2020.02.01NOIP普及模拟4】怪兽

    [2020.02.01NOIP普及模拟4]怪兽 文章目录 [2020.02.01NOIP普及模拟4]怪兽 题目描述 输入 输出 输入输出样例 数据范围限制 提示 解析 code 题目描述 PYWBKT ...

  2. 【 BowWow and the Timetable CodeForces - 1204A 】【思维】

    题目链接 可以发现 十进制4 对应 二进制100 十进制16 对应 二进制10000 十进制64 对应 二进制1000000 可以发现每多两个零,4的次幂就增加1. 用string读入题目给定的二进制 ...

  3. 【35.02%】【codeforces 734A】Vladik and flights

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  5. [原创] 【2014.12.02更新网盘链接】基于EasySysprep4.1的 Windows 7 x86/x64 『视频』封装

    [原创] [2014.12.02更新网盘链接]基于EasySysprep4.1的 Windows 7 x86/x64 『视频』封装 joinlidong 发表于 2014-11-29 14:25:50 ...

  6. zw版【转发·台湾nvp系列Delphi例程】HALCON HWindowX 02

    zw版[转发·台湾nvp系列Delphi例程]HALCON HWindowX 02 procedure TForm1.Button1Click(Sender: TObject);var img : H ...

  7. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

  8. 【中途相遇法】【STL】BAPC2014 K Key to Knowledge (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...

  9. 【链表】【模拟】Codeforces 706E Working routine

    题目链接: http://codeforces.com/problemset/problem/706/E 题目大意: 给一个N*M的矩阵,Q个操作,每次把两个同样大小的子矩阵交换,子矩阵左上角坐标分别 ...

随机推荐

  1. aop 中joinpoint的使用方法

    一.簡述下joinpoint在不同情況下的不同: 1.在around中可以用,此時可以執行被包裹的代碼,可以根據情況來判斷是否執行被包裹的代碼,以實現控制的作用. public void around ...

  2. ArcGIS Engine检索要素集、要素类和要素

    转自原文 ArcGIS Engine检索要素集.要素类和要素 /// <summary> /// 获取所有要素集 /// </summary> /// <param na ...

  3. Android——解决port占用问题导致的模拟器无法识别

    遇到一个问题:昨天模拟器工作还正常,今天eclipse就识别不了了.后来发现是360手机助手占用了5555port造成的,我就纳闷了,平时这个也不是自己主动启动.今天就启动了.废话不多说,就几个步骤就 ...

  4. ellipsize-TextView省略号的设定

    ellipsize主要是当TextView的文字过长的时候,我们可以让它显示省略号 用法如下: 在xml中 <!--省略号在结尾--> android:ellipsize = " ...

  5. Android学习笔记之详细讲解画圆角图片

    package xiaosi.RoundConcer; import android.app.Activity; import android.graphics.Bitmap; import andr ...

  6. select发生改变使用js提交form表单(get传值)

    form表单如下: <form id="my_form" method="get" action=""> <input t ...

  7. Linux与好莱坞电影

    Linux与好莱坞电影         2009年底上映的<阿凡达>是电影特效的巅峰之作,除此之外还有<2012>每次观看之后总能让我们热血沸腾.      很早以前电影特效都 ...

  8. CF-833B The Bakery(线段树优化Dp)

      Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredie ...

  9. 【Codeforces Round #452 (Div. 2) B】Months and Years

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 闰,平,平 平,闰,平 平,平,闰 平,平,平 4种情况都考虑到就好. 可能有重复的情况. 但是没关系啦. [代码] #includ ...

  10. 【2017 Multi-University Training Contest - Team 7】Kolakoski

    [Link]:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1011&cid=765 [Description] 有一种 ...