(UVA) 12626 - I ❤ Pizza - Solução

import java.io.*;
import java.util.*;

class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main processando = new Main();
        processando.takeInput();
       
        System.exit(0);
    }
   
    void takeInput() throws NumberFormatException, IOException {
        String line = "";
        StringTokenizer tokenizer = null;
       
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
        line = br.readLine();
        tokenizer = new StringTokenizer(line);
        int n = Integer.parseInt(tokenizer.nextToken());
       
        int contador = 0;
        while (contador < n) {
            int[] qte = new int[6];
           
            String[] vetor = new String[1];
            vetor[0] = "";
            vetor[0] = br.readLine();
                       
            for (int i = 0; i < vetor[0].length(); i++) {
                if (vetor[0].charAt(i) == 'A') {
                    qte[0]++;
                }
                else if (vetor[0].charAt(i) == 'M') {
                    qte[1]++;
                }
                else if (vetor[0].charAt(i) == 'R') {
                    qte[2]++;
                }
                else if (vetor[0].charAt(i) == 'G') {
                    qte[3]++;
                }
                else if (vetor[0].charAt(i) == 'T') {
                    qte[4]++;
                }
                else if (vetor[0].charAt(i) == 'I') {
                    qte[5]++;
                }
            }
           
            int[] novo = new int[6];
           
            for (i = 0; i < 6; i++) {
                if (i == 0) {
                    novo[i] = qte[i]/3;
                }
                else if (i == 2) {
                    novo[i] = qte[i]/2;
                }
                else { 
                    novo[i] = qte[i];
                }
            }
           
            Arrays.sort(novo);
           
            System.out.println(novo[0]);
           
            contador++;
        }       
       
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução