寒假集训个人赛 D
2018-01-09 09:16
218 查看
D - War of the Corporations
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
SubmitStatus
use MathJax to parse formulas
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
Input
Output
Input
Output
Input
Output
Hint
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".
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
SubmitStatus
use MathJax to parse formulas
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
Input
intellect tell
Output
1
Input
google apple
Output
0
Input
sirisiri sir
Output
2
Hint
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<stdio.h> #include<string.h> #include<algorithm> using namespace std; const int N=1e5+5; char p ,g ; int main() { while(~scanf("%s%s",p,g)) { int longa=strlen(p); int length=strlen(g); int i,j,sum=0; for(i=0;i<=longa-1;i++) { if(p[i]==g[0]) { int k=i+1; for(j=1;j<=length-1;j++,k++) { if(p[k]!=g[j]||k>longa) break; } if(j==length) { sum++; i+=length-1; } } } printf("%d\n",sum); } return 0; }
相关文章推荐
- SDUT - 2017年寒假集训 阶段测试赛3(个人) -- 解题报告
- 寒假集训个人赛 A
- 寒假集训个人赛 E
- 寒假集训之树状数组
- 寒假集训 Day2 F Wooden Sticks HDU1051:木条排序
- 1.26寒假集训(并查集三连←.←)-2
- 1.28寒假集训(玩树)-2
- 2017级寒假ACM集训结训赛--官方题解
- 暑假集训-个人赛第一场
- 【2018寒假集训 Day2】【动态规划】维修栅栏
- 2013寒假ACM集训_最短路
- ACMer菜鸟的ACM寒假集训感悟
- hdu 2097 Sky数 寒假集训1 06
- SDUT_2015寒假集训_BFS&DFS_J-Catch That Cow
- 个人寒假作业项目《印象笔记》第二天
- 暑假集训——个人训练赛04——A题
- 寒假集训——二分查找,哈希查找
- 2014寒假ACM集训13级PK赛-翻转排序
- (寒假集训) 不等数列
- 2017寒假集训-小题训练1:A - Magic Spheres