SHARE
TWEET

Untitled

a guest Oct 21st, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. const unsigned long long P = 131;
  7.  
  8. int main() {
  9.     //freopen("input.txt", "r", stdin);
  10.     int n;
  11.     string s1, s2;
  12.     cin >> n >> s1 >> s2;
  13.     n--;
  14.     for(int i = 0; i < n; i++) {
  15.         if (s2[i] == 'N') {
  16.             s2[i] = 'S';
  17.         } else if (s2[i] == 'S') {
  18.             s2[i] = 'N';
  19.         } else if (s2[i] == 'W') {
  20.             s2[i] = 'E';
  21.         } else if (s2[i]=='E') {
  22.             s2[i] = 'W';
  23.         }
  24.        
  25.     }
  26.  
  27.     unsigned long long pow = 1;
  28.     unsigned long long h1 = 0, h2 = 0;
  29.     for (int i = n - 1; i >= 0; i--) {
  30.         h1 = h1 + (s1[i]) * pow;
  31.         h2 = h2 * P + s2[i];
  32.         if (h1 == h2)
  33.         {
  34.             cout << "NO" << endl;
  35.             return 0;
  36.         }
  37.         pow *= P;
  38.     }
  39.     cout << "YES" << endl;
  40.     return 0;
  41. }
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