Iamtui1010

prefix

Nov 7th, 2021
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.95 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<fstream>
  4. #include<vector>
  5. #include<string>
  6. #include<algorithm>
  7.  
  8. #define long long long
  9. #define nln '\n'
  10.  
  11. const long BASE = 311;
  12. const long MOD = 1e9 + 3;
  13.  
  14. using namespace std;
  15.  
  16. // GLobal variables: f1, f2, st1, st2
  17.  
  18. fstream f1,f2;
  19.  
  20. inline void openf()
  21. {
  22.     f1.open("prefix.inp", ios:: in);
  23.     f2.open("prefix.out", ios:: out);
  24. }
  25.  
  26. inline void closef()
  27. {
  28.     f1.close();
  29.     f2.close();
  30. }
  31.  
  32. string st1, st2;
  33.  
  34. long hst1 = 0;
  35. long hst2 = 0;
  36.  
  37. void data()
  38. {
  39.     f1.tie(0)->sync_with_stdio(0);
  40.     f2.tie(0)->sync_with_stdio(0);
  41.     cin >> st1 >> st2;
  42.     for (long i = 0; i != st1.size(); ++i)
  43.     {
  44.         hst2 = ((hst2*BASE) + st2[i] - 'a') % MOD;
  45.         hst1 = ((hst1*BASE) + st1[i] - 'a') % MOD;
  46.     }
  47. }
  48.  
  49. void process()
  50. {
  51.     if (hst1 == hst2)
  52.         cout << "Yes" << nln;
  53.     else
  54.         cout << "No" << nln;
  55. }
  56.  
  57. void view()
  58. {
  59. }
  60.  
  61. int main()
  62. {
  63.     openf();
  64.     data();
  65.     process();
  66.     view();
  67.     closef();
  68.     return 0;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment