fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. var cCFPB;
  5. cCFPB = (function () {
  6. var makeAPartBytes, makeBytes;
  7. cCFPB.debug = false;
  8. function cCFPB(sDirtyBytes) {
  9. var arr;
  10. arr = makeAPartBytes(sDirtyBytes);
  11. var times = function (a,x) { var out=[]; while(x>0) { out = out.concat(a); x-- }; return out }
  12. arr = times(arr, 50);
  13. console.log('Length of input arr: ' + arr.length);
  14. makeBytes(arr, 8);
  15. }
  16.  
  17. makeAPartBytes = function (arg) {
  18. var arr, typeArg;
  19. typeArg = typeof arg;
  20. if (typeArg === 'string') {
  21. console.log('Check string!');
  22. arr = arg.match(/\S\w*|\S\w*\S|\w*\S/g);
  23. }
  24. if (typeArg === 'Array') {
  25. console.log('Check Array!');
  26. arr = arg;
  27. }
  28. if ((typeArg !== 'string') && (typeArg !== 'Array')) {
  29. console.log('Check not string and not Array!');
  30. }
  31. return arr;
  32. };
  33. makeBytes = function (arr, lengthDef, aElem, length, x, numCall) {
  34. var alnt, e, elem, i, iter, prnt, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _results;
  35. if (numCall == null) {
  36. numCall = 0;
  37. }
  38. ++numCall;
  39. if (numCall > 8) {
  40. return;
  41. }
  42. if (typeof x === 'undefined') {
  43. x = 0;
  44. }
  45. if (cCFPB.debug) {
  46. console.log("===========" + numCall + "===========");
  47. }
  48. _results = [];
  49. for (i = _i = 0, _len = arr.length; _i < _len; i = ++_i) {
  50. elem = arr[i];
  51. if (!(i > x)) {
  52. continue;
  53. }
  54. if (cCFPB.debug) {
  55. if (typeof iter === 'undefined') {
  56. iter = 0;
  57. }
  58. ++iter;
  59. console.log("|---Iter:" + iter + "----");
  60. console.log("|Pass summ leng: " + length);
  61. }
  62. if (typeof length === 'undefined') {
  63. length = 0;
  64. }
  65. if (typeof aElem === 'undefined') {
  66. aElem = [];
  67. }
  68. length = elem.length + length;
  69. if (cCFPB.debug) {
  70. console.log("|Summ length: " + length);
  71. console.log("|Curr elem: " + elem + ' :: ' + elem.length);
  72. }
  73. if (length < lengthDef) {
  74. if (cCFPB.debug) {
  75. console.log('|Check: < ');
  76. console.log('|New cycle!');
  77. }
  78. if (cCFPB.debug) {
  79. console.log('|' + aElem);
  80. }
  81. aElem.push(elem);
  82. length = 0;
  83. for (_j = 0, _len1 = aElem.length; _j < _len1; _j++) {
  84. e = aElem[_j];
  85. length = length + e.length;
  86. }
  87. makeBytes(arr, lengthDef, aElem, length, i, numCall);
  88. }
  89. if (length > lengthDef) {
  90. if (cCFPB.debug) {
  91. console.log('|Check: >');
  92. }
  93. length = 0;
  94. for (_k = 0, _len2 = aElem.length; _k < _len2; _k++) {
  95. e = aElem[_k];
  96. length = length + e.length;
  97. }
  98. continue;
  99. }
  100. if (length == lengthDef) {
  101. if (cCFPB.debug) {
  102. console.log("|Check: =!!!!!!!!!!=");
  103. }
  104. aElem.push(elem);
  105. alnt = aElem.length;
  106. for (i = _l = 0, _len3 = aElem.length; _l < _len3; i = ++_l) {
  107. e = aElem[i];
  108. if (cCFPB.debug) {
  109. console.log('|InPrnt:' + e);
  110. }
  111. if (typeof prnt === 'undefined') {
  112. prnt = '';
  113. }
  114. if (i + 1 === alnt) {
  115. prnt = prnt + e;
  116. } else {
  117. prnt = prnt + e + '+';
  118. }
  119. }
  120. prnt = prnt;
  121. aElem = [];
  122. length = 0;
  123. for (_m = 0, _len4 = aElem.length; _m < _len4; _m++) {
  124. e = aElem[_m];
  125. length = length + e.length;
  126. }
  127. //console.log("|Byte: " + prnt);
  128. _results.push(prnt = '');
  129. } else {
  130. _results.push(void 0);
  131. }
  132. }
  133. return _results;
  134. };
  135. return cCFPB;
  136. })();
  137.  
  138. process.stdin.on('data', function (chunk) {
  139. var data = '';
  140. data+=chunk;
  141. new cCFPB(data);
  142. });
  143.  
Success #stdin #stdout 0.13s 38112KB
stdin
01010 0111 0100 1010 001 0000 0100 1011 1100 1010 10101
stdout
Check string!
Length of input arr: 550