Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. long long int t,x,y,ex,ey,i,j,tf=0;
  6. cin>>t>>x>>y>>ex>>ey;
  7. string a;
  8. cin>>a;
  9. for(i=0;i<t+1;i++)
  10. {
  11. if(x==ex&&y==ey)
  12. {
  13. cout<<i<<endl;
  14. tf++;
  15. break;
  16. }
  17. if(x<ex&&a[i]=='E'&&x!=ex)
  18. {
  19. x=x+1;
  20. }
  21. if(x>ex&&a[i]=='W'&&x!=ex)
  22. {
  23. x=x-1;
  24. }
  25. if(y<ey&&a[i]=='N'&&y!=ey)
  26. {
  27. y=y+1;
  28. }
  29. if(y>ey&&a[i]=='S'&&y!=ey)
  30. {
  31. y=y-1;
  32. }
  33. //cout<<x<<y;
  34. }
  35. if(tf==0)
  36. {
  37. cout<<-1<<endl;
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement