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;
}

最新文章

  1. mingw64环境搭建
  2. js this 闭包
  3. [原创] zabbix学习之旅二:yum安装
  4. android-serialport-api and libusb for android
  5. HW4.3
  6. LigerUI API
  7. iOS_SN_Socket - AsyncSocket
  8. sqlserver关联更新问题
  9. dynamics 365 AI 解决方案 —— 微软布局
  10. SpringBoot(三)_controller的使用
  11. c++ boost 苹果内购 IAP验证
  12. Naive Bayes 笔记
  13. java实验项目报告
  14. 下载tensorflow-gpu版本的源
  15. Oracle 用脚本安装第二个数据库
  16. 23 正则表达式和re模块
  17. JBoss Data Grid 7.2 在OpenShift环境中的Quick Start
  18. centos7安装MySQL5.7无法设置密码问题
  19. css揭秘读书笔记
  20. GAN背后的数学原理

热门文章

  1. 经验之谈—让你看明确block
  2. 热点共享SS网络
  3. js13--对象、原型
  4. regular-第一课(正则表达式基础)
  5. elasticsearch的master选举机制
  6. Linux架设Jsp环境
  7. JavaScript--数据结构之栈
  8. 读阮一峰《ECMAScript 6 入门》小结
  9. IOIOI卡片占卜(Atcoder-IOIOI カード占い)(最短路)
  10. linux网络防火墙-iptables基础详解