-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBeekeeper.java
More file actions
51 lines (43 loc) · 1002 Bytes
/
Copy pathBeekeeper.java
File metadata and controls
51 lines (43 loc) · 1002 Bytes
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Success in 0.09s
import java.util.Scanner;
public class Beekeeper{
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int n = reader.nextInt();
while(n != 0){
String longest = "bb";
int doubles = -1;
for(int i = 0; i < n; i++){
String word = reader.next();
int d = Count(word);
if(d > doubles){
doubles = d;
longest = word;
}
}
System.out.println(longest);
n = reader.nextInt();
}
reader.close();
}
private static int Count(String word){
int doubles = 0;
for(int i = 0; i < word.length() - 1; i++)
if(word.charAt(i) == word.charAt(i + 1) && IsVowel(word.charAt(i)))
doubles++;
return doubles;
}
private static boolean IsVowel(char c){
switch(c){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'y':
return true;
default:
return false;
}
}
}