Codeforces Round #342 (Div. 2) b. War of the corporations (greedy)

Source: Internet
Author: User

Transmission Door

Description

A long time ago, in a galaxy far far away, giant it-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the Corner:gogol are 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 as long as possible. Finally, they found out, that's the name of the new artificial intelligence is similar to the name of the phone, that's pineap Ple released years ago. As all rights on their name belong to Pineapple, they stand on changing the name of Gogol ' s artificial intelligence.

Pineapple insists, that's the name of the their phone occurs in the name of AI as a substring. Because The name of technology is already printed on all devices, the Gogol's director decided to replace some characters In the AI name with "#". As this operation are pretty expensive, you should find the minimum number of characters-replace with '# ', such that The name of the 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 the AI designed by Gogol, its length doesn ' t exceed, characters. S Econd line contains the name of the phone released by Pineapple-years ago, its length doesn ' t exceed 30. Both string is non-empty and consist of only small Chinese letters.

Output

Print the minimum number of characters that must is replaced with "#" on order to obtain that the name of the phone do ESN ' t occur in the name of AI as a substring.

Sample Input
Intellect
Tell

Google
Apple

Sirisiri
Sir
Sample Output
1

0

2
Note

In the first sample AI ' s name is replaced with "int#llect".

In the second sample Gogol can just keep things as they is.

In the third sample one of the new possible names of AI is "s#ris#ri".

Ideas

Test instructions

Given the string A and string B, ask at least how many characters to modify so that string A does not have a substring of b

Exercises

Sweep from start to finish, when the substring of string a appears the same as B, modify the last character as much as possible, making the final result minimal. For example: A:sisisis b:sis A strategy like this, you only need to modify two characters.

#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 (greedy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.