Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package aa_umss_17_nov_17_34505;
- import java.io.IOException;
- import java.util.Scanner;
- /**
- *
- * @author Roger Flores Vargas
- */
- public class MessageDecoding_213 {
- public static void main(String[] args) {
- int[] unos = {0, 1, 3, 7, 15, 31, 63, 127};
- int[] keys = {0, 0, 1, 4, 11, 26, 57, 120};
- Scanner entrada = new Scanner(System.in);
- String header, message;
- int tam, ind, key, j;
- boolean seguir;
- while(entrada.hasNextLine()){
- do{
- header = entrada.nextLine();
- }while(header.length() == 0);
- message = "";
- do{
- message += entrada.nextLine();
- }while(message.length() < 3 || !message.substring(message.length() - 3).equals("000"));
- j = 0;
- while (j < message.length()) {
- tam = bin2dec(message.substring(j, j + 3));
- j += 3;
- seguir = true;
- while (seguir && j < message.length()) {
- key = bin2dec(message.substring(j, j + tam));
- seguir = key != unos[tam];
- if(seguir){
- ind = keys[tam] + key;
- System.out.print(header.charAt(ind));
- }
- j += tam;
- }
- }
- System.out.println();
- }
- }
- private static int bin2dec(String bin) {
- return Integer.parseInt(bin, 2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement