Posts

(SPOJ) 18550 - Troco - Solução

Solução utilizando o "problema da mochila". É possível ver como isso funciona através do link: http://pt.wikipedia.org/wiki/Problema_da_mochila import java.io.*; import java.util.*; class Main {     public static void main(String[] args) throws NumberFormatException, IOException {         Main processando = new Main();         processando.processa();                 System.exit(0);     }         static int leitor(BufferedReader br) throws NumberFormatException, IOException {         int n;         int resp = 0;                  while (true) {             n = br.read();    ...

(SPOJ) 1390 - Mini-Poker - Solução

import java.io.*; import java.util.*; class Main {     public static void main(String[] args) throws NumberFormatException, IOException {         Main processando = new Main();         processando.processa();                  System.exit(0);     }          static int leitor(BufferedReader br) throws NumberFormatException, IOException {         int n;         int resp = 0;                  while (true) {             n = br.read();             if (n >= '0' && n <= '9') break;         ...

Estruturas

Exemplo de pilha: Stack<Character> pilha = new Stack<>(); (deprecated) Usar: Deque<Character> pilha = new ArrayDeque<>(); http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html Usar um Stack é mais eficiente do que utilizar um ArrayList como se fosse uma pilha. Exemplo de lista: ArrayList<Integer> lista = new ArrayList<>(); http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

Leitor de inteiros

static int leitor(BufferedReader br) throws NumberFormatException, IOException {         int n;         int resp = 0;         int sinal = 1;         while (true) {             n = br.read();             if (n >= '0' && n <= '9') break;             if (n == '-') sinal = -1;             if (n == '+') sinal = 1;         }         while (true) {             resp = resp*10 + n-'0';             n = br.read();     ...

(SPOJ) 11014 - Expressões - Solução

import java.io.*; import java.util.*; import java.lang.*; class Main {     public static void main(String[] args) throws NumberFormatException, IOException {         Main processando = new Main();         processando.processa();                 System.exit(0);     }         static int leitor(BufferedReader br) throws NumberFormatException, IOException {         int n;         int resp = 0;         while (true) {             n = br.read();             if (n >= '0' && n <= '9')             ...

(SPOJ) 3830 - Soma - Solução 2

import java.io.*; import java.util.*; class Main {     public static void main(String[] args) throws NumberFormatException, IOException {         Main processando = new Main();         processando.processa();                System.exit(0);     }        static int leitor(BufferedReader br) throws NumberFormatException, IOException {         int n;         int resp = 0;         int sinal = 1;         while (true) {             n = br.read();             if (n >= '0' && n <= '9') break;       ...

(SPOJ) 840 - Cofrinhos da Vó Vitória - Solução 2

import java.io.*; import java.util.*; import java.lang.Math; import java.math.*; class Main {     public static void main(String[] args) throws NumberFormatException, IOException {         Main processando = new Main();         processando.processa();                 System.exit(0);     }         static int leitor(BufferedReader br) throws NumberFormatException, IOException {         int n;         int resp = 0;         while (true) {             n = br.read();             if (n >= '0' && n <= '9')            ...