PS/Baekjoon Online Judge

[백준 13939] Imena [Java]

kimyoungrok 2024. 7. 18. 16:08
728x90

문제

Little Mirko likes to type and often gets bored during class, which is why his teacher assigned him a task.

Mirko must retype a book​ that contains N space-separated sentences. In this book, a sentence​ is an array of one or more space-separated words, where only the last word’s character is a punctuation mark ( '.', '?' or '!' ). The rest of the words do not contain punctuation marks.

Words are arrays of characters​, either lowercase or uppercase letters of the English alphabet, or digits or, exceptionally, a punctuation mark at the end of the last word in the sentence.

Although he likes typing sentences, Mirko doesn’t like typing names. A name​ is a word that starts with an uppercase letter of the English alphabet, whereas the rest of the characters are lowercase letters of the English alphabet, except the last character, which can be the punctuation mark. Before he decides to retype the whole thing, Mirko wants to know how many names there are in each sentence of the book​. Write a programme to help him! 

입력

The first line of input contains the integer N (1 ≤ N ≤ 5), the number from the task.

The second line contains N sentences from the book. The total number of characters in the book will not exceed 1000. 

출력

You must output N lines. The i th line contains the number of names in the i th sentence. 


풀이

. ! ? 으로 구분되는 여러 문자열들에 대해 숫자가 포함되지 않으면서도 첫 글자가 대문자인 단어(이름)의 수를 출력하면 된다.

우선 여러 문자열은 하나의 문자열로 주어지므로 입력받아서 . ! ? 으로 분리해주자.

N은 필요없다.

 

각 문자열의 양쪽 공백을 제거하고, 공백을 기준으로 분리해 모든 단어를 살펴보아야 한다.

각 단어의 첫 글자가 대문자이고, 숫자가 포함이 안되었는지 확인해 갯수를 세어주자.


소스코드

보기


출처

https://www.acmicpc.net/problem/13939

728x90