Problem
Given a sentence in English, output the counts of consonants and vowels.
Vowels are letters in [’A’,’E’,’I’,’O’,’U’,’a’,’e’,’i’,’o’,’u’].
Input
The test file starts with an integer S(1 ≤ S ≤ 100), the number of sentences.
Then follow S lines, each containing a sentence - words of length 1 to 20 separated by spaces. Every sentence will contain at least one word and be comprised only of characters [a-z][A-Z] and spaces. No sentence will be longer than 1000 characters.
Output
For each sentence, output the number of consonants and vowels on a line, separated by space.
Solution
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
class Bakjoon {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n=sc.nextInt();
int jaum=0;
int moum=0;
for(int i=0;i<=n;i++) {
String input =sc.nextLine().trim().toLowerCase().replaceAll(" ","");
for(int j=0;j<input.length();j++) {
if(input.charAt(j)=='a'||input.charAt(j)=='e'||input.charAt(j)=='i'||input.charAt(j)=='o'||input.charAt(j)=='u') {
moum++;
}
else {
jaum++;
}
}
if(jaum!=0 &&moum!=0) {
System.out.println(jaum+" "+moum);
jaum=0;moum=0;
}
}
}
}
|
https://www.acmicpc.net/problem/11319
반응형
'Algorithms > BOJ[Java]' 카테고리의 다른 글
[백준/17009번] Winning Score ( CCC 2019 Junior Division)[Java] (0) | 2019.12.09 |
---|---|
[백준/13597번] Tri-du( A Primeira Fase da Maratona de Programação 2015) [Java] (0) | 2019.12.09 |
[백준/11104번] Fridge of Your Dreams ( IDI Open 2007 )[Java] (0) | 2019.12.09 |
[백준/5988번] 홀수일까 짝수일까 [Java] (0) | 2019.12.09 |
[백준/10669번] 오늘 날짜 [Java] (0) | 2019.12.09 |