Codeforces Round #342 (Div. 2)-B. War of the Corporations
2016-02-16 10:48
316 查看
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”.
在原字符中至少增添多少个#使得没有第二个字符串,暴力即可
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
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; }
相关文章推荐
- 寒假作业之三
- C/S架构和B/S架构的概念和区别
- 2014年多校联合题目总结【留着开学刷套题用】
- android应用实现虚线
- React native 学习
- springMVC集成mongoDB的demo
- 深入理解RunLoop
- rhel6 用户管理命令
- getResource()和getResourceAsStream以及路径问题
- SpringMVC整合MongoDB开发 高级操作
- 超键、主键、候选键
- 滥用图片博客做 C&C 配置
- JavaScript基础知识<三>
- Oracle 启动监听命令
- MongoDB一般安装
- iOS开发中“此证书的签发者无效”的解决方案
- 搜索引擎指令介绍
- 基于MVC4+EasyUI的Web开发框架形成之旅--界面控件的使用
- RedHat安装g++
- 数据结构(陈越)-网易云课堂 第一周编程题