Skip to content

Commit aea2264

Browse files
done more questions
1 parent aab78b9 commit aea2264

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

sail.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
int main(){
5+
int n,sx,sy,ex,ey;
6+
cin>>n>>sx>>sy>>ex>>ey;
7+
8+
string s;
9+
cin>>s;
10+
int ans = 0;
11+
12+
if(sx == ex && sy == ey){
13+
cout<<ans<<endl;
14+
return 0;
15+
}
16+
17+
18+
int i=0;
19+
while((ex != sx || ey != sy) && i < s.size()){
20+
ans++;
21+
if(sx < ex && s[i] == 'E') sx++;
22+
else if(sy < ey && s[i] == 'N') sy++;
23+
else if(sx > ex && s[i] == 'W') ex++;
24+
else if(sy > ey && s[i] == 'S') ey++;
25+
i++;
26+
}
27+
if(ex == sx && ey == sy)
28+
cout<<ans<<endl;
29+
else cout<<-1<<endl;
30+
return 0;
31+
}

0 commit comments

Comments
 (0)