Search Wizard

시간 제한1초메모리 제한2048 MB

요약
공백으로 나뉜 단어들로 이루어진 문자열 S에서 짧은 단어 W가 겹쳐서 나타나도 포함해 몇 번 등장하는지 센다.
난이도

쉬움10점 중 3점

유형
문자열, 문자열 매칭, 구현
정답자
아직 제출이 없습니다

문제

You adore word searches, and have been doing them since you were little. You do them so much, you started just picking out words whenever you see a string of text! With a target string WW in mind, can you figure out how many times WW occurs in the string SS?

Note that instances of WW may overlap partially, but every occurance has a unique starting index in SS.

입력

The first line consists of a string WW (1≤∣W∣≤101≤|W|≤10). The second line contains a single integer MM (1≤M≤1051≤M≤10^5). The third and final line contains the string SS consisting of MM words. Consecutive words are separated by a single space. The total length of all words in SS is at most 10510^5. The only characters that will appear in WW and all words in SS are lowercase alphabetical characters a - z.

출력

Return an integer of the number of times WW occurs in SS, allowing for overlap.

예제3

  1. 예제 1

    입력
    buzz
    8
    bee buzz bee buzz bee buzz bee buz
    
    예상 출력
    3
    
  2. 예제 2

    입력
    aaa
    5
    aaaaaaaa aa a aaaa aaa
    
    예상 출력
    9
    
  3. 예제 3

    입력
    aba
    3
    aba ababa abba
    
    예상 출력
    3