문제

문제 1322

[문자열] 단어 찾아보기1

시간 제한 1.000초 메모리 제한 128MB

문제 설명

제출 시 금지 단어
split
여러 개의 문장이 주어질 때, 제시된 단어로 시작하는 문장이 몇 개인지 찾아보자.

입력 설명

첫 번째 줄에 문장의 수 n과 찾고자 하는 단어가  입력된다.
두 번째 줄부터 n줄에 걸쳐 n개의 문장이 입력된다.


출력 설명

입력된 단어로 시작하는 문장의 수가 출력된다.

입력 예시

5 This
There are many possibilities, but we need to choose the best one.
This is a beautiful morning with a clear blue sky.
This book I'm reading is full of interesting facts about history.
There seems to be a misunderstanding about the purpose of this meeting.
We need to assess the impact of this new policy on our business operations.

출력 예시

2

힌트

re.search함수는 정규식을 통해 탐색할 문자열를 표현할 수 있다.
찾고자 하는 문자열의 앞에 ^를 붙이면 가장 처음 오는 문자열을 의미한다.
ex) re.search(‘^this’,”this is book”)

출처

문자열(py)