-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoweltoLenght.java
More file actions
61 lines (52 loc) · 1.64 KB
/
voweltoLenght.java
File metadata and controls
61 lines (52 loc) · 1.64 KB
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
52
53
54
55
56
57
58
59
60
61
package FML;
import java.util.Scanner;
public class voweltoLenght {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numInputs = Integer.parseInt(sc.nextLine());
String bestFood = "";
int bestVowels = 1;
int bestLenght = 1;
//float bestRatio = 1;
for (int i = 0; i < numInputs; i++) {
String currentFood = sc.nextLine();
int currentVowels = vowelCounter(currentFood);
int currentLenght = currentFood.length();
//System.out.printf("%s %d/%d", currentFood, currentVowels, currentLenght);
//System.out.println();
float currentRatio = currentVowels / (float) currentLenght;
float bestRatio = bestVowels / (float) bestLenght;
//System.out.printf("cur %f - best %f", currentRatio, bestRatio);
//System.out.println();
if (currentRatio < bestRatio) {
bestFood = currentFood;
bestVowels = currentVowels;
bestLenght = currentLenght;
} else if (currentRatio == bestRatio) {
if (currentVowels > bestVowels) {
bestFood = currentFood;
bestVowels = currentVowels;
bestLenght = currentLenght;
} else if (currentVowels == bestVowels) {
if (currentLenght > bestLenght) {
bestFood = currentFood;
bestVowels = currentVowels;
bestLenght = currentLenght;
}
}
}
}
System.out.printf("%s %d/%d", bestFood, bestVowels, bestLenght);
}
static boolean isVowel(char ch) {
ch = Character.toLowerCase(ch);
return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
static int vowelCounter(String str) {
int count = 0;
for (int i = 0; i < str.length(); i++)
if (isVowel(str.charAt(i)))
count++;
return count;
}
}