B. War of the Corporations

题目连接:

http://www.codeforces.com/contest/625/problem/B

Description

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.

Sample Input

intellect

tell

Sample Output

1

Hint

题意

给你s1 s2,你每次操作可以使得s1串中某个字符变成#,然后问你最小修改多少次,就可以使得s1中不含有s2子串

题解:

贪心,我们每次修改最后一个字符就好了

这样相交的一定都被修改了

代码

#include<bits/stdc++.h>
using namespace std; string s1,s2;
int main()
{
cin>>s1>>s2;
int ans = 0;
for(int i=0;i<s1.size();i++)
{
int flag = 0;
for(int j=0;j<s2.size();j++)
{
if(i+j>s1.size())
{
flag = 1;
break;
}
if(s1[i+j]!=s2[j])
{
flag = 1;
break;
}
}
if(flag==0)
{
s1[i+s2.size()-1]='#';
ans++;
}
}
cout<<ans<<endl;
}

Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心的更多相关文章

  1. Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)

    传送门 Description A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Go ...

  2. Codeforces Round #342 (Div. 2)-B. War of the Corporations

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  3. Codeforces Round #342 (Div. 2)

    贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...

  4. Codeforces Round #342 (Div. 2) B

    B. War of the Corporations time limit per test 1 second memory limit per test 256 megabytes input st ...

  5. Codeforces Round #342 (Div. 2) D. Finals in arithmetic 贪心

    D. Finals in arithmetic 题目连接: http://www.codeforces.com/contest/625/problem/D Description Vitya is s ...

  6. Codeforces Round #342 (Div. 2) C. K-special Tables 构造

    C. K-special Tables 题目连接: http://www.codeforces.com/contest/625/problem/C Description People do many ...

  7. Codeforces Round #342 (Div. 2) A - Guest From the Past 数学

    A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...

  8. Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟

    E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...

  9. Codeforces Round #342 (Div. 2) D. Finals in arithmetic(想法题/构造题)

    传送门 Description Vitya is studying in the third grade. During the last math lesson all the pupils wro ...

随机推荐

  1. 整合git与wingIDE(代码下载)

    通过多次被IDE的闪退崩溃甚至无教程调教后,我深刻认识到开发wingIDE这种IDE的小公司,在很多功能方面就是个坑…… 所以,如果你的电脑比较好,运行pycharm无压力,建议略过此文,直接去用py ...

  2. 机器学习中的算法-决策树模型组合之随机森林与GBDT

    机器学习中的算法(1)-决策树模型组合之随机森林与GBDT 版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使 ...

  3. 离线树状数组 hihocoder 1391 Countries

    官方题解: // 离线树状数组 hihocoder 1391 Countries #include <iostream> #include <cstdio> #include ...

  4. java 抽象类和接口

    接口和内部类为我们提供了一种将接口与实现分离的更加结构化的方法. 抽象类与接口是java语言中对抽象概念进行定义的两种机制,正是由于他们的存在才赋予java强大的面向对象的能力.他们两者之间对抽象概念 ...

  5. qt信号signal和槽slot机制

    内容: 一.概述 二.信号 三.槽 四.信号与槽的关联 五.元对象工具 六.程序样例 七.应注意的问题 信号与槽作为QT的核心机制在QT编程中有着广泛的应用,本文介绍了信号与槽的一些基本概念.元对象工 ...

  6. QS之warning message

    Multiple message categories are specified as a comma separated list.

  7. spark的环境安装

    1.安装sbt 正常安装流程. 在cmd里运行的时候,要提前设置代理(如果上网有代理),set JAVA_OPTS=-Dhttp.proxySet=true -Dhttp.proxyHost=172. ...

  8. error while loading shared libraries: lib******: cannot open shared object file: No such file or directory

    程序编译成功后,运行时错误: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object fi ...

  9. 实体框架 (EF) 入门 => 五、连接和模型

    public class BloggingContext : DbContext  {  public BloggingContext()          : base("name=Blo ...

  10. usb库文件usb_desc.c分析

    参考<圈圈教你玩USB> usb协议中使用的是小端结构,所以实际数据在传输时是低字节在先的. 设备描述符的实现: 已知每个设备都必须有且仅有一个设备描述符,它的结构在USB协议中有详细的定 ...