Guest User

C

a guest
Apr 18th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. /*Sawal nahi hone wala phir bhi kar lo ek try*/
  4. #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  5. #define ll long long
  6. #define db double
  7. #define ld long double
  8. #define rep(i,n) for(ll i=0;i<n;i++)
  9. #define rev(i,n) for(ll i=n;i>=0;i--)
  10. #define rep_a(i,a,n) for(ll i=a;i<n;i++)
  11. #define pb push_back
  12. #define sz(v) ((int)(v).size())
  13. #define all(v) (v).begin(), (v).end()
  14. #define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0);
  15. #define debugg(x,y) do { std::cerr << #x << ": " << x << "  "<< #y << ": " << y << std::endl; } while (0);
  16. const ll some = 1000000000;
  17. ll ansr = 1;
  18. ll ansc = 1;
  19. void movement(ll N,ll E)
  20. {
  21.     if (N>0)
  22.     {
  23.         N = N%some;
  24.         ansr = ansr + N;
  25.         if(ansr>some)
  26.         ansr = ansr%some;
  27.     }
  28.     else if(N<0)
  29.     {
  30.         N = N*-1;
  31.         N = N%some;
  32.         ansr -= N;
  33.         if(ansr<=0)
  34.         {
  35.             ansr +=some;
  36.         }
  37.     }
  38.     if (E>0)
  39.     {
  40.         E = E%some;
  41.         ansc = ansc + E;
  42.         if(ansc>some)
  43.         ansc = ansc%some;
  44.     }
  45.     else if(E<0)
  46.     {
  47.         E *= -1;
  48.         E = E%some;
  49.         ansc -= E;
  50.         if(ansc<=0)
  51.         {
  52.             ansc +=some;
  53.         }
  54.     }
  55. }
  56. int solve()
  57. {
  58.    int t;
  59.    
  60.    cin>>t;
  61.    int c = 0;
  62.    while(t--)
  63.    {
  64.        c++;
  65.        ansr = 1;
  66.        ansc = 1;
  67.        cout<<"Case #"<<c<<": ";
  68.        string s;
  69.        cin>>s;
  70.        ll row = 1 , col = 1;
  71.        vector<ll> stk;
  72.        ll mul  = 1;
  73.        rep(i,s.length())
  74.        {
  75.            if((s[i]>='0')&&(s[i]<='9'))
  76.            {
  77.                stk.push_back((long long)(s[i] - '0'));
  78.                mul *= (long long)(s[i] - '0');
  79.                mul  = mul%some;
  80.            }
  81.            else if(s[i] == ')')
  82.            {
  83.                stk.pop_back();
  84.                mul = 1;
  85.                rep(j,stk.size())
  86.                {
  87.                    mul *= stk[j];
  88.                    mul = mul%some;
  89.                }
  90.                mul = mul % some;
  91.            }
  92.            else if(s[i]=='N')
  93.            {
  94.                movement(-mul,0);
  95.            }
  96.            else if(s[i]=='S')
  97.            {
  98.                movement(mul,0);
  99.            }
  100.            else if(s[i]=='E')
  101.            {
  102.                movement(0,mul);
  103.            }
  104.            else if(s[i]=='W')
  105.            {
  106.                movement(0,-mul);
  107.            }
  108.            else
  109.            {
  110.                continue;
  111.            }
  112.            
  113.        }
  114.        cout<<ansc<<" "<<ansr<<endl;
  115.    }
  116.    return 0;    
  117. }
  118.  
  119. int main()
  120. {
  121.     fast;
  122. //  #ifndef ONLINE_JUDGE
  123. //  freopen("input.txt", "r", stdin);
  124. //  freopen("output.txt", "w", stdout);
  125. //  #else
  126. //  #endif
  127.     solve();
  128. //  #ifndef ONLINE_JUDGE
  129. //  cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC <<" Sec\n";
  130. //  #endif
  131.     return 0;
  132. }
Add Comment
Please, Sign In to add comment