Advertisement
rafv

Untitled

Nov 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package aa_umss_17_nov_17_34505;
  7.  
  8. import java.io.IOException;
  9. import java.util.Scanner;
  10.  
  11. /**
  12. *
  13. * @author Roger Flores Vargas
  14. */
  15. public class MessageDecoding_213 {
  16. public static void main(String[] args) {
  17. int[] unos = {0, 1, 3, 7, 15, 31, 63, 127};
  18. int[] keys = {0, 0, 1, 4, 11, 26, 57, 120};
  19. Scanner entrada = new Scanner(System.in);
  20. String header, message;
  21. int tam, ind, key, j;
  22. boolean seguir;
  23. while(entrada.hasNextLine()){
  24. do{
  25. header = entrada.nextLine();
  26. }while(header.length() == 0);
  27. message = "";
  28. do{
  29. message += entrada.nextLine();
  30. }while(message.length() < 3 || !message.substring(message.length() - 3).equals("000"));
  31. j = 0;
  32. while (j < message.length()) {
  33. tam = bin2dec(message.substring(j, j + 3));
  34. j += 3;
  35. seguir = true;
  36. while (seguir && j < message.length()) {
  37. key = bin2dec(message.substring(j, j + tam));
  38. seguir = key != unos[tam];
  39. if(seguir){
  40. ind = keys[tam] + key;
  41. System.out.print(header.charAt(ind));
  42. }
  43. j += tam;
  44. }
  45. }
  46. System.out.println();
  47. }
  48.  
  49. }
  50.  
  51. private static int bin2dec(String bin) {
  52. return Integer.parseInt(bin, 2);
  53. }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement