Codeforces Round #342 (Div. 2)-B. War of the Corporations
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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.
Sample test(s)
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 <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <set>
#include <map>
#include <list>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int>PII;
typedef vector<int>VI;
typedef vector<LL>VL;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const double Pi = acos(-1.0);
char str[100100];
char c[40];
int main()
{
scanf("%s %s",str,c);
int len = strlen(str);
int ans = 0;
for(int i=0;i<len;i++)
{
if(str[i]==c[0])
{
int k;
for( k=0;c[k]!='\0';k++)
{
if(str[i+k]!=c[k])
{
break;
}
}
if(c[k]=='\0')
{
ans++;
i=i+k-1;
}
}
}
printf("%d\n",ans);
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(贪心)
传送门 Description A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Go ...
- 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 ...
随机推荐
- ASP.NET Web Api
1.参考资料 Routing in Asp.NET Web Api: http://www.asp.net/web-api/overview/web-api-routing-and-actions/r ...
- Linq to Sql : 并发冲突及处理策略
原文:Linq to Sql : 并发冲突及处理策略 1. 通过覆盖数据库值解决并发冲突 try { db.SubmitChanges(ConflictMode.ContinueOnConflict) ...
- SQL Server 常用日期查询语句
--本月月初select dateadd(mm,datediff(mm,0,getdate()),0) --本月月末select DATEADD(DD,-1,DATEADD(MONTH,1+DAT ...
- MAC破解软件
作为一个iOS程序开发的工程师,我们需要的是那些辅助的利器 但是这些利器确实需要高价购买的 reveal系统层级关系 Charles网络抓包破解 蓝灯(FQ必备) 小黑冒(搜索必备) Cornerst ...
- 一个js获取数组下标的函数
或许,面试的时候,你可能会被问到怎么模拟字符串的indexOf()函数获取数组的下标,这里是个人实现的一个小函数,里面包含的知识点挺多的,假如是新手,看不懂的地方可以百度,这里就不做详细介绍了,当然, ...
- centos7作为web服务器优化
centos7作为web服务器优化 原文 http://itindex.net/detail/51140-centos7-web-服务器 1.加大打开文件数的限制(open files) 查看 uli ...
- sqlserver日志的备份与还原
----------完整备份与还原---------- --完整备份数据库--backup database studb to disk='e:\stu.bak'back ...
- composer [ReflectionException] Class Fxp\Composer\AssetPlugin\Repository\NpmRepository does not exist
在执行composer update时报错 [ReflectionException]Class Fxp\Composer\AssetPlugin\Repository\NpmRepository d ...
- 记一次MVC4站点在IIS上部署的诡异问题
最近朋友的公司遇到一个站点部署问题, 朋友从事服务器维护多年,说也是花了十多天仍为解决. 经多次尝试未果,仍报错如下: 我询问了相关情况,确认了该网站是VS2013开发的,版本为,NET Framew ...
- HBA相关知识
HBA使用详解: 一般的AIX客户端支持的HBA为Emulex HBA卡和交换机硬件确保连接成功的标志: A. 如果是 Emulex卡,卡上的绿灯常亮,黄灯闪烁. B. 如果是 QLogic卡,卡上的 ...