SHARE
TWEET

Untitled

a guest Nov 19th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require("fs");
  2. let S ="";
  3. let T = "";
  4. let inp = fs.readFileSync("C:\\Users\\Dmitry\\Desktop\\JSS\\ХЕШ\\input.txt", "utf8").split("\n");
  5. S = inp[0];
  6. T = inp[1];
  7.  
  8. var ht = 0;
  9. var hs = 0;
  10. var r = 0;
  11. var n = S.length;
  12. var m = T.length;
  13. r = m - 1;
  14. st2 = 1;
  15. let result = "";
  16. while(r >= 0){
  17.     ht += T.charCodeAt(r) * st2;
  18.     hs += S.charCodeAt(r) * st2;
  19.     r = r - 1;
  20.     st2 = st2 * 2;
  21. }
  22.  
  23. st2 = st2 / 2;
  24. var i = 0;
  25. while(i <= n - m){
  26.     if(hs == ht){
  27.         j = 0;
  28.         while((S.charAt(i+j) == T.charAt(j)) && (j < m)){
  29.             j++;
  30.         }
  31.         if(j == m){
  32.             result+=((i+1)+" ");
  33.         }
  34.     }
  35.     i++
  36.     if(i <= n-m){
  37.         hs = (hs - S.charCodeAt(i - 1) * st2) * 2 + S.charCodeAt(i + m - 1);
  38.     }
  39. }
  40. console.log(S);
  41. console.log(T);
  42. console.log(result);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top