forked from BitsPleaseMSI/BitsPlease-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.cpp
36 lines (33 loc) · 910 Bytes
/
9.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
#include <iostream>
#include <string>
using namespace std;
int main()
{
string directions;
int str_size,msize,mid_x,mid_y,x=0,y=0,total=0;
getline(cin,directions);
str_size=directions.length();
msize=(2*str_size)+1;
int gmap[msize][msize]={}; //to initialize array with all elements=0
mid_x=mid_y=msize/2;
gmap[mid_x][mid_y]=1; //since starting position is
//considered a house
for(int i=0;i<msize;i++)
{
if(directions[i]=='<')
y--;
else if(directions[i]=='>')
y++;
else if(directions[i]=='^')
x--;
else if(directions[i]=='V')
x++;
if(gmap[mid_x+x][mid_y+y]==0)
{
gmap[mid_x+x][mid_y+y]=1; //thanks to Animesh Ghosh for better count loop
total++;
}
}
cout<<total+1;
return 0;
}