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 ...
 
随机推荐
- ORA-02266: unique/primary keys in table referenced by enabled foreign keys
			
在数据库里面使用TRUNCATE命令截断一个表的数据时,遇到如下错误 SQL >TRUNCATE TABLE ESCMOWNER.SUBX_ITEM ORA-02266: unique/prim ...
 - MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems
			
早晨宁波那边的IT人员打电话告知数据库无法访问了.其实我在早晨也发现Ignite监控下的宁波的数据库服务器出现了异常,但是当时正在检查查看其它服务器发过来的各类邮件,还没等到我去确认具体情 ...
 - C#:委托和自定义事件
			
1. 委托概述 “委托”相当于C++中的“函数指针”,委托必须与所要“指向”的函数在“参数”和“返回类型”上保持一致; // 定义Person类 public class Person { publi ...
 - jquery打造自定义控件(原创)
			
本人第一次发表文章,不足之出请大家多多包涵 下面是一个combox的代码 /// <reference path="../Js/jquery-1.7.2.min.js" /& ...
 - logback配置详解1
			
一:根节点<configuration>包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配置文 ...
 - 《小白的CFD之旅》招募写手
			
<小白的CFD之旅>系列招募写手. 由于工作繁忙,<小白的CFD之旅>系列更新缓慢,现招募志愿者写手.这是一个分享平台,欢迎各位愿意分享自己CFD学习经历的朋友们. <小 ...
 - 第37课 深度解析QMap与QHash
			
1. QMap深度解析 (1)QMap是一个以升序键顺序存储键值对的数据结构 ①QMap原型为 class QMap<K, T>模板 ②QMap中的键值对根据Key进行了排序 ③QMap中 ...
 - iOS 2D绘图 (Quartz2D)之路径(stroke,fill,clip,subpath,blend)
			
像往常一样 这个系列的博客是跟着大神的脚步来的.按照往例 在此贴出原博客的出处: http://blog.csdn.net/hello_hwc?viewmode=list我对大神的崇拜之情 如滔滔江水 ...
 - web端功能测试总结(一)
			
一.功能测试 1.1链接测试 链接是web应用系统的一个很重要的特征,主要是用于页面之间切换跳转,指导用户去一些不知道地址的页面的主要手段,链接测试一般关注三点: 1)链接是否按照既定指示那样,确实链 ...
 - down的另一种用法