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 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
intellecttell
googleapple
sirisirisir
Sample Output
1 0 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".
思路
题意:
给出字符串a和字符串b,问至少修改多少个字符,使得字符串a没有一个子串为b
题解:
从头到尾扫一遍,当出现字符串a的子串与b相同,尽可能修改最后的字符,使得最后结果最小。例如:a: sisisis b: sis 这样的策略下,只需修改两个字符即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100005;
char a[maxn];
char b[35],tmp[35];
int main()
{
int cnt = 0;
scanf("%s %s",a,b);
int lena = strlen(a);
int lenb = strlen(b);
for (int i = 0;i <= lena - lenb;)
{
strncpy(tmp,a+i,lenb);
if (strcmp(tmp,b) == 0)
{
cnt++;
i += lenb;
}
else
{
i++;
}
}
printf("%d\n",cnt);
return 0;
}
Codeforces Round #342 (Div. 2) B. War of the Corporations(贪心)的更多相关文章
- Codeforces Round #342 (Div. 2) B. War of the Corporations 贪心
B. War of the Corporations 题目连接: http://www.codeforces.com/contest/625/problem/B Description A long ...
- Codeforces Round #342 (Div. 2)-B. War of the Corporations
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces Round #342 (Div. 2)
贪心 A - Guest From the Past 先买塑料和先买玻璃两者取最大值 #include <bits/stdc++.h> typedef long long ll; int ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #342 (Div. 2) E. Frog Fights set 模拟
E. Frog Fights 题目连接: http://www.codeforces.com/contest/625/problem/E Description stap Bender recentl ...
- 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 ...
随机推荐
- 转载文章-----Rational Rose2007(v7.0)下载地址、安装及激活详解教程(图)
转载地址:http://www.cnblogs.com/leaven/p/3718361.html 最近需要画uml图,之前用的是Rose 2003版的,由于好久没进去了,结果发现原来的激活又失效了, ...
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path解决方案
0.环境: win7系统,Tomcat9配置无误. 1.错误: 项目中某一.jps页面忽然出现错误,鼠标点上去为:The superclass "javax.servlet.http.Htt ...
- 搭建一个Mongodb (Windows) 版本
因为有项目需要借助nosql 做一个中间层,所以选择了Mongodb 来搞,其实之前呢已经搭建过这部分的环境,这次再次搭建也是记录一下,当时给自己的一个扫盲123教程 借助Mongodb 其实也是缓存 ...
- linux命令详解:md5sum命令
前言 在网络传输.设备之间转存.复制大文件等时,可能会出现传输前后数据不一致的情况.这种情况在网络这种相对更不稳定的环境中,容易出现.那么校验文件的完整性,也是势在必行的. 使用说明 md5sum命令 ...
- OpenStack云计算快速入门之三:OpenStack镜像管理
原文:http://blog.chinaunix.net/uid-22414998-id-3272059.html 第三部分 OpenStack镜像管理 一.简介 很多源都有为OpenStack已经编 ...
- centos 6.6 使用tomcat6部署solr5.3.1
Solr现在是一个独立的服务器. 从Solr5.0开始,Solr不再发布为在任何Servlet容器中部署的“war”Web应用程序包(Web Application Archive).网上关于solr ...
- [AJAX]ajax在兼容模式下失效解决办法
使用jQuery,用ajax实现局部刷新功能,在火狐,360急速浏览器高速模式下,ie8,9都能正常运行,但切换到兼容模式下无效,解决办法有两种关闭浏览器兼容性视图,二是引入json2.js文件 这里 ...
- UVA - 11584 Partitioning by Palindromes[序列DP]
UVA - 11584 Partitioning by Palindromes We say a sequence of char- acters is a palindrome if it is t ...
- 大牛的博客 osharp以及EF的分析
http://www.cnblogs.com/guomingfeng/ http://developer.51cto.com/art/201309/409950_all.htm
- Chrome 控制台console的用法(转)
下面我们来看看console里面具体提供了哪些方法可以供我们平时调试时使用. 目前控制台方法和属性有: ["$$", "$x", "dir" ...