Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- /* CASO DE TESTE:
- aeiou
- o rato roeu a roupa do rei de roma
- 4310
- t3st3 p4r4 c0d1f1c4r
- kwy
- the quick brown fox jumps over the lazy dog
- */
- public class Main {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- List<String> alfabetos = new ArrayList<>();
- List<String> frases = new ArrayList<>();
- while(sc.hasNextLine()) {
- String alfabeto = sc.nextLine().trim().toLowerCase();
- String frase = sc.nextLine().trim().toLowerCase();
- if (frase.isEmpty() || alfabeto.isEmpty()) {
- break;
- }
- alfabeto = alfabeto.replaceAll("\\s+",""); // apagar os espaços em branco
- alfabetos.add(alfabeto);
- frases.add(frase);
- }
- for (int i = 0; i < frases.size(); i++) {
- String alfabeto = alfabetos.get(i);
- String frase = frases.get(i);
- boolean temCaractereInvalido = false;
- int contador = 0;
- for (char caractereAlfabeto : alfabeto.toCharArray()) {
- if (!Character.isLetterOrDigit(caractereAlfabeto)) {
- temCaractereInvalido = true;
- }
- for (char caractereEntrada : frase.toCharArray()) {
- if ((caractereAlfabeto == caractereEntrada)) {
- contador++;
- }
- }
- }
- if (!temCaractereInvalido) {
- System.out.println(contador);
- }
- }
- sc.close();
- }
- }
Add Comment
Please, Sign In to add comment