Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- /*Sawal nahi hone wala phir bhi kar lo ek try*/
- #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
- #define ll long long
- #define db double
- #define ld long double
- #define rep(i,n) for(ll i=0;i<n;i++)
- #define rev(i,n) for(ll i=n;i>=0;i--)
- #define rep_a(i,a,n) for(ll i=a;i<n;i++)
- #define pb push_back
- #define sz(v) ((int)(v).size())
- #define all(v) (v).begin(), (v).end()
- #define debug(x) do { std::cerr << #x << ": " << x << std::endl; } while (0);
- #define debugg(x,y) do { std::cerr << #x << ": " << x << " "<< #y << ": " << y << std::endl; } while (0);
- const ll some = 1000000000;
- ll ansr = 1;
- ll ansc = 1;
- void movement(ll N,ll E)
- {
- if (N>0)
- {
- N = N%some;
- ansr = ansr + N;
- if(ansr>some)
- ansr = ansr%some;
- }
- else if(N<0)
- {
- N = N*-1;
- N = N%some;
- ansr -= N;
- if(ansr<=0)
- {
- ansr +=some;
- }
- }
- if (E>0)
- {
- E = E%some;
- ansc = ansc + E;
- if(ansc>some)
- ansc = ansc%some;
- }
- else if(E<0)
- {
- E *= -1;
- E = E%some;
- ansc -= E;
- if(ansc<=0)
- {
- ansc +=some;
- }
- }
- }
- int solve()
- {
- int t;
- cin>>t;
- int c = 0;
- while(t--)
- {
- c++;
- ansr = 1;
- ansc = 1;
- cout<<"Case #"<<c<<": ";
- string s;
- cin>>s;
- ll row = 1 , col = 1;
- vector<ll> stk;
- ll mul = 1;
- rep(i,s.length())
- {
- if((s[i]>='0')&&(s[i]<='9'))
- {
- stk.push_back((long long)(s[i] - '0'));
- mul *= (long long)(s[i] - '0');
- mul = mul%some;
- }
- else if(s[i] == ')')
- {
- stk.pop_back();
- mul = 1;
- rep(j,stk.size())
- {
- mul *= stk[j];
- mul = mul%some;
- }
- mul = mul % some;
- }
- else if(s[i]=='N')
- {
- movement(-mul,0);
- }
- else if(s[i]=='S')
- {
- movement(mul,0);
- }
- else if(s[i]=='E')
- {
- movement(0,mul);
- }
- else if(s[i]=='W')
- {
- movement(0,-mul);
- }
- else
- {
- continue;
- }
- }
- cout<<ansc<<" "<<ansr<<endl;
- }
- return 0;
- }
- int main()
- {
- fast;
- // #ifndef ONLINE_JUDGE
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- // #else
- // #endif
- solve();
- // #ifndef ONLINE_JUDGE
- // cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC <<" Sec\n";
- // #endif
- return 0;
- }
Add Comment
Please, Sign In to add comment