G - G CodeForces - 625B(贪心)

G - G CodeForces - 625B(贪心)

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”.

思路

  • 分析:要想改动次数最小的话,只需要在没次查找到目标串的时候,在把这个目标串的最后一个字符改成‘#’就行了

代码

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
void fre() { freopen("A.txt","r",stdin), freopen("Ans.txt","w",stdout); }
#define ll long long 
const int mxn = 400;
const int INF = 0x3f3f3f3f;

int main()
{
    /* fre(); */
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int lt = t.size();

    int pos = s.find(t, 0);
    int num = 0;
    while(pos != string::npos)
    {
        num ++;
        pos = s.find(t, pos + lt);
    }
    cout << num << endl;

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值