Advertisement
Guest User

Untitled

a guest
Aug 18th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.46 KB | None | 0 0
  1. #include<algorithm>
  2. #include<iostream>
  3. #include<iomanip>
  4. #include<stdio.h>
  5. #include<bitset>
  6. #include<vector>
  7. #include<string>
  8. #include<queue>
  9. #include<cmath>
  10. #include<ctime>
  11. #include<stack>
  12. #include<map>
  13. #include<set>
  14. using namespace std;
  15. typedef long long LL;
  16. typedef long double LD;
  17. typedef pair<LL,LL> PLL;
  18. typedef pair<LD,LD> PDD;
  19. typedef pair<int,int> PII;
  20. typedef pair<PII,PII> PPII;
  21. #define PRINT(a) cerr<<#a<<" = "<<(a)<<'\n'
  22. #define B_E(a) a.begin(), a.end()
  23. #define PB push_back
  24. #define MP make_pair
  25. #define S second
  26. #define F first
  27. inline void file() {
  28.     #ifdef _WIN32
  29.         srand(time(NULL));
  30.         return;
  31.     #endif
  32.  
  33.     ios_base::sync_with_stdio(false);
  34.     cin.tie(NULL);
  35.     cout.tie(NULL);
  36.  
  37.     if (0) {
  38.         freopen(".in",  "r", stdin);
  39.         freopen(".out", "w", stdout);
  40.     }
  41. }
  42. inline void read(int& n) {
  43.     #define nxt h = getchar_unlocked()
  44.     #define nxt h = getchar()
  45.     char h; n = 0;
  46.     for (nxt; h<'0' || h>'9'; nxt);
  47.     for (; h>='0' && h<='9'; nxt)
  48.         n = n*10 + h-'0';
  49.     #undef nxt
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56. const clock_t MAXT = (100*CLOCKS_PER_SEC)/1000;
  57. const int   PX[8] = {1,0,-1,0,  1,1,-1,-1},
  58.             PY[8] = {0,1,0,-1,  -1,1,1,-1},
  59.             N = 1e5 + 10,
  60.             INF = 1e9,
  61.             MOD = 1e9 + 7;
  62. const LL    INFL = 1e18,
  63.             MODL = 1e9 + 7;
  64. const LD    EPS = 1e-6;
  65.  
  66. inline int rnd(int l = 0, int r = INF) {
  67.     unsigned ans = rand();
  68.     ans = (ans<<8) ^ rand();
  69.     ans = (ans<<8) ^ rand();
  70.     ans = (ans<<8) ^ rand();
  71.     ans %= r-l+1;
  72.     return int(ans + l);
  73. }
  74.  
  75.  
  76. int n;
  77.  
  78.  
  79. inline LL get(string s) {
  80.     s = " " + s;
  81.     for (int i=n; i; --i)
  82.         switch (s[i]) {
  83.         case 'A':
  84.             s[i] = 0;
  85.             break;
  86.         case 'B':
  87.             s[i] = 1;
  88.             break;
  89.         case 'C':
  90.             s[i] = 2;
  91.             break;
  92.         case 'D':
  93.             s[i] = 0;
  94.             break;
  95.         case 'E':
  96.             s[i] = 1;
  97.             break;
  98.         }
  99.     //for (int i=1; i<=n; ++i) cout<<+s[i]; cout<<'\n';
  100.  
  101.     LL ans = 0;
  102.     for (int i=1; i<=n; ++i) {
  103.         if ( !(i&1) ) ans *= 2;
  104.             else ans *= 3;
  105.  
  106.         ans += s[i];
  107.     }
  108.  
  109.     return ans;
  110. }
  111.  
  112.  
  113. inline LL solve(LL l, LL r) {
  114.     if ( l == r )
  115.         return 0;
  116.  
  117.     if ( r < l )
  118.         swap(l,r);
  119.  
  120.     return r - l - 1;
  121. }
  122.  
  123.  
  124. main()
  125. { file();
  126.  
  127.  
  128.  
  129.  
  130.     string s;
  131.     LL l,r;
  132.  
  133.     cin>>s;
  134.     n = s.size();
  135.     l = get(s);
  136.  
  137.     cin>>s;
  138.     r = get(s);
  139.  
  140.     cerr<<' '<<l<<' '<<r<<'\n';
  141.  
  142.     cout<<solve(l,r)<<'\n';
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement