(URI) Encaixa ou Não I - Solução

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

class Main  {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       
        int qte = leitor(br);
       
        for (int i = 0; i < qte; i++) {
            String s = br.readLine();
            String[] ss = s.split(" ");
           
            boolean encaixa = true;
            if (ss[1].length() <= ss[0].length()) {
                int ultimo = ss[0].length()-1;
                for (int j = ss[1].length()-1; j >= 0; j--, ultimo--) {
                    if (ss[1].charAt(j) != ss[0].charAt(ultimo)) {
                        encaixa = false;
                    }
                }
            }
            else {
                encaixa = false;
            }
           
            if (encaixa) {
                System.out.println("encaixa");
            }
            else {
                System.out.println("nao encaixa");
            }               
        }
    }
   
    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();
           if (n < '0' || n > '9') break;
       }

       return resp*sinal;
    }
}

Comments

Popular posts from this blog

(Coderbyte) Dash Insert II - Solução

(Coderbyte) Run Length - Solução

(Coderbyte) Counting Minutes I - Solução