Advertisement
warma2d

Странное сравнение

Mar 29th, 2024 (edited)
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const readline = require('readline');
  2. const io_interface = readline.createInterface({
  3.     input: process.stdin
  4. });
  5.  
  6. let lineNumber = 0,
  7.     s,
  8.     t;
  9.  
  10. io_interface.on('line', function(line) {
  11.     if (lineNumber === 0) {
  12.         s = line;
  13.     } else if (lineNumber < 2) {
  14.         t = line;
  15.     }
  16.     lineNumber++;
  17. })
  18.  
  19. io_interface.on('close', function() {
  20.     if (isStrangeEqual(s, t)) {
  21.         console.log('YES');
  22.     } else {
  23.         console.log('NO');
  24.     }
  25. })
  26.  
  27. function isStrangeEqual(s, t) {
  28.         if (s.length !== t.length) {
  29.             return false;
  30.         }
  31.         let map = {};
  32.         for (const index in s) {
  33.             if (!map.hasOwnProperty(s[index].charCodeAt(0))) {
  34.                 map[s[index].charCodeAt(0)] = t[index].charCodeAt(0);
  35.             } else {
  36.                 if (map[s[index].charCodeAt(0)] !== t[index].charCodeAt(0)) {
  37.                     return false;
  38.                 }
  39.             }
  40.         }
  41.  
  42.         return true;
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement