Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- long long int t,x,y,ex,ey,i,j,tf=0;
- cin>>t>>x>>y>>ex>>ey;
- string a;
- cin>>a;
- for(i=0;i<t+1;i++)
- {
- if(x==ex&&y==ey)
- {
- cout<<i<<endl;
- tf++;
- break;
- }
- if(x<ex&&a[i]=='E'&&x!=ex)
- {
- x=x+1;
- }
- if(x>ex&&a[i]=='W'&&x!=ex)
- {
- x=x-1;
- }
- if(y<ey&&a[i]=='N'&&y!=ey)
- {
- y=y+1;
- }
- if(y>ey&&a[i]=='S'&&y!=ey)
- {
- y=y-1;
- }
- //cout<<x<<y;
- }
- if(tf==0)
- {
- cout<<-1<<endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement