-
Notifications
You must be signed in to change notification settings - Fork 1
/
Robot Path Decoding.cpp
103 lines (98 loc) · 1.58 KB
/
Robot Path Decoding.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include<cmath>
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
int32_t main()
{
IOS
int T;
cin>>T;
for(int t=0;t<T;t++)
{
string str,res="";
cin>>str;
int r=1,c=1;
// cout<<str<<endl;
int act=1,active=0;
for(int i=0;i<str.length();i++)
{
if(str[i] == 'N')
{
if(r==1)
{
r = 1000000000;
}else
{
r = r - 1;
}
}else if(str[i] == 'S')
{
if(r==1000000000)
{
r = 1;
}else
{
r = r + 1;
}
}else if(str[i] == 'E')
{
if(c==1000000000)
{
c = 1;
}else
{
c = c + 1;
}
}else if(str[i] == 'W')
{
if(c==1)
{
c = 1000000000;
}else
{
c = c - 1;
}
}else
{
int ct = str[i] - '0';
string pre = str.substr(0,i);
int cn=0,j;
for(j = i+1;j<str.length();j++)
{
if(str[j] == '(')
{
cn++;
}
if(str[j] == ')')
{
cn--;
}
if(cn==0)
{
break;
}
}
// cout<<"J->"<<j<<"Str[j]"<<str[j]<<endl;
string mid;
string post = str.substr(j+1,str.length());
// cout<<"Pre->"<<pre<<endl;
// cout<<"Mid->"<<mid<<endl;
// cout<<"Post->"<<post<<endl;
while(ct>0)
{
mid = mid + str.substr(i+2,j-i-2);
ct--;
}
str = pre + mid + post;
// cout<<"str->>"<<str<<endl;
i=i-1;
// break; //------------------------------------------
}
}
// cout<<"str->>"<<str<<endl;
cout<<"Case #"<<t+1<<": "<<c<<" "<<r<<endl;
}
return 0;
}