(SPOJ) 11605 - Botas perdidas - Solução

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

class Main {
    class Sapato {
        public int e;
        public int d;
    }
   
    public static void main(String[] args) throws NumberFormatException, IOException {
        Main processando = new Main();
        processando.processa();
       
        System.exit(0);
    }
   
    void processa() throws NumberFormatException, IOException {
        String line = "";
       
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
        while ((line = br.readLine()) != null) {
            Sapato[] sapato = new Sapato[31];
           
            for (int i = 0; i < 31; i++) {
                sapato[i] = new Sapato();
            }
           
            StringTokenizer tokenizer = new StringTokenizer(line);
            int qteSapatos = Integer.parseInt(tokenizer.nextToken());
       
            for (int i = 0; i < qteSapatos; i++) {
                line = br.readLine();
                tokenizer = new StringTokenizer(line);
               
                int numero = Integer.parseInt(tokenizer.nextToken()) - 30;
                String peTmp = tokenizer.nextToken();
                char pe = peTmp.charAt(0);

                if (pe == 'E') {
                    sapato[numero].e++;
                }
                else {
                    sapato[numero].d++;
                }                       
            }
           
            int qtePares = 0;           
            for (int i = 0; i < 31; i++) {
                qtePares += Math.min(sapato[i].e, sapato[i].d);
            }
           
            System.out.println(qtePares);
        }
                      
        return;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução