fork(4) download
  1.  
  2. //////package volume7;
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.math.BigInteger;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10.  
  11. public class Main { /// Fibinary Numbers --- UNSOLVED
  12.  
  13. static Map<Integer, BigInteger> fibo;
  14.  
  15. public static void main(String[] args) throws IOException {
  16. fibo = fibo();
  17. StringBuilder sb = new StringBuilder();
  18. String line = "";
  19. while(true) {
  20.  
  21. String a = br.readLine();
  22. String b = br.readLine();
  23.  
  24.  
  25. BigInteger bigA = BigInteger.ZERO;
  26. BigInteger bigB = BigInteger.ZERO;
  27.  
  28. bigA = getDecimal(a, bigA);
  29. bigB = getDecimal(b, bigB);
  30.  
  31.  
  32. BigInteger bigResult = BigInteger.ZERO;
  33. bigResult = bigResult.add(bigA).add(bigB);
  34.  
  35.  
  36. String result = "";
  37. if(bigResult.compareTo(BigInteger.ZERO) == 0) {
  38. sb.append("0" + "\n\n");
  39. } else {
  40. result = getFibinary(bigResult, result); /// get fibinay
  41. sb.append(result + "\n\n");
  42. }
  43.  
  44. if((line = br.readLine()) == null) break;
  45.  
  46. }
  47. sb.deleteCharAt(sb.length() - 1);
  48. System.out.print(sb);
  49.  
  50. }
  51.  
  52.  
  53. public static String getFibinary(BigInteger bigResult, String result) {
  54. int helper = 0;
  55. for (int i = 100; i >= 1; i--) {
  56. BigInteger temp = fibo.get(i);
  57. if (bigResult.compareTo(temp) >= 0) {
  58. result = result + "1";
  59. bigResult = bigResult.subtract(temp);
  60. helper++;
  61. } else if(helper > 0)
  62. result = result + "0";
  63. }
  64. return result;
  65. }
  66.  
  67.  
  68. public static BigInteger getDecimal(String a, BigInteger bigA) {
  69. for (int i = 0; i < a.length(); i++) {
  70. if (a.charAt(i) == '1') {
  71. bigA = bigA.add(fibo.get(a.length() - i));
  72. }
  73. }
  74. return bigA;
  75. }
  76.  
  77.  
  78. public static HashMap<Integer, BigInteger> fibo() {
  79. HashMap<Integer, BigInteger> fibo = new HashMap<Integer, BigInteger>();
  80. fibo.put(1, new BigInteger(1+""));
  81. fibo.put(2, new BigInteger(2+""));
  82. for(int i = 3; i <= 100; i++) {
  83. fibo.put(i, fibo.get(i-1).add(fibo.get(i-2)));
  84. }
  85.  
  86. return fibo;
  87.  
  88. }
  89.  
  90. }
  91.  
  92.  
Success #stdin #stdout 0.08s 380160KB
stdin
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010
1010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010
stdout
1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111