danielmrcl

Vogais Extraterrestres

Mar 5th, 2021
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. /* CASO DE TESTE:
  4. aeiou
  5. o rato roeu a roupa do rei de roma
  6. 4310
  7. t3st3 p4r4 c0d1f1c4r
  8. kwy
  9. the quick brown fox jumps over the lazy dog
  10. */
  11.  
  12. public class Main {
  13.  
  14.     public static void main(String[] args) {
  15.         Scanner sc = new Scanner(System.in);
  16.        
  17.         List<String> alfabetos = new ArrayList<>();
  18.         List<String> frases = new ArrayList<>();
  19.  
  20.         while(sc.hasNextLine()) {
  21.             String alfabeto = sc.nextLine().trim().toLowerCase();
  22.             String frase = sc.nextLine().trim().toLowerCase();
  23.  
  24.             if (frase.isEmpty() || alfabeto.isEmpty()) {
  25.                 break;
  26.             }
  27.  
  28.             alfabeto = alfabeto.replaceAll("\\s+",""); // apagar os espaços em branco
  29.  
  30.             alfabetos.add(alfabeto);
  31.             frases.add(frase);
  32.         }
  33.  
  34.         for (int i = 0; i < frases.size(); i++) {
  35.             String alfabeto = alfabetos.get(i);
  36.             String frase = frases.get(i);
  37.             boolean temCaractereInvalido = false;
  38.  
  39.             int contador = 0;
  40.  
  41.             for (char caractereAlfabeto : alfabeto.toCharArray()) {
  42.                 if (!Character.isLetterOrDigit(caractereAlfabeto)) {
  43.                   temCaractereInvalido = true;
  44.                 }
  45.              
  46.                 for (char caractereEntrada : frase.toCharArray()) {
  47.                     if ((caractereAlfabeto == caractereEntrada)) {
  48.                         contador++;
  49.                     }
  50.                 }
  51.             }
  52.            
  53.             if (!temCaractereInvalido) {
  54.               System.out.println(contador);
  55.             }
  56.         }
  57.  
  58.         sc.close();
  59.     }
  60. }
Add Comment
Please, Sign In to add comment