Advertisement
Guest User

Vowel to Length Ratio_Solution_2

a guest
Aug 17th, 2022
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static char[] vowels = {'a', 'e', 'o', 'u', 'i'};
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner scanner = new Scanner(System.in);
  8.         int times = Integer.parseInt(scanner.nextLine());
  9.  
  10.         if (1 <= times && times <= 20) {
  11.             String[] inputs = new String[times];
  12.             for (int i = 0; i < inputs.length; i++) {
  13.                 inputs[i] = scanner.nextLine();
  14.             }
  15.             System.out.println(ratio(inputs)+" "+vowelCounter(ratio(inputs))+"/"+letterCounter(ratio(inputs)));
  16.         }
  17.     }
  18.  
  19.     public static boolean isVowel(char c) {                   // проверява дали е гласната
  20.         c = Character.toLowerCase(c);
  21.  
  22.         for (char d : vowels) {
  23.             if (c == d)
  24.                 return true;
  25.         }
  26.         return false;
  27.     }
  28.  
  29.     public static int vowelCounter(String a) {               //калкулира гласните
  30.         char[] box = a.toCharArray();
  31.         int vowelCounter = 0;
  32.         for (int i = 0; i < box.length; i++) {
  33.             if (isVowel(box[i])) {
  34.                 vowelCounter++;
  35.             }
  36.         }
  37.         return vowelCounter;
  38.     }
  39.  
  40.     public static int letterCounter(String b) {             //калкулира букбите
  41.         int letterCounter = 0;
  42.         for (int i = 0; i < b.length(); i++) {
  43.             letterCounter++;
  44.         }
  45.         return letterCounter;
  46.     }
  47.  
  48.     public static String ratio(String [] a){               //главната проверка
  49.         String output = a[0];
  50.         for (int i = 1; i < a.length; i++) {
  51.             if (vowelCounter(a[i]) > vowelCounter(output) && letterCounter(a[i]) < letterCounter(output)){
  52.                 output = a[i];
  53.             } if (vowelCounter(a[i]) == vowelCounter(output) && letterCounter(a[i]) == letterCounter(output) || vowelCounter(a[i]) == 0 && vowelCounter(output) ==0 || letterCounter(a[i]) == letterCounter(output)){
  54.                 output = theLongest(a);
  55.             }
  56.         }
  57.         return output;
  58.     }
  59.  
  60.     public static String theLongest(String[] a){          //най-дългата дума
  61.         String output = a[0];
  62.         for (int i = 0; i < a.length; i++) {
  63.             if (a[i].length() > output.length()){
  64.                 output = a[i];
  65.             }
  66.         }
  67.         return output;
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement