Advertisement
a53

Traseu2

a53
Jul 25th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include <fstream>
  2. #include <cstring>
  3. using namespace std;
  4. int a[103][103];
  5.  
  6. int main()
  7. {
  8. ifstream fin("traseu2.in");
  9. ofstream fout("traseu2.out");
  10. int n,l,c,i,j,ok=0;
  11. char s[251];
  12. fin>>n;
  13. fin>>l>>c;
  14. for(i=1;i<=n;i++)
  15. for(j=1;j<=n;j++)
  16. fin>>a[i][j];
  17. fin>>s;
  18. for(i=0;i<strlen(s)&&ok==0;i++)
  19. {
  20. if(s[i]=='E'&&a[l][c+1]==0)
  21. c++;
  22. if(s[i]=='V'&&a[l][c-1]==0)
  23. c--;
  24. if(s[i]=='N'&&a[l-1][c]==0)
  25. l--;
  26. if(s[i]=='S'&&a[l+1][c]==0)
  27. l++;
  28. if(l>n)
  29. {
  30. l--;
  31. ok=1;
  32. }
  33. if(l==0)
  34. {
  35. l++;
  36. ok=1;
  37. }
  38. if(c>n)
  39. {
  40. c--;
  41. ok=1;
  42. }
  43. if(c==0)
  44. {c++;
  45. ok=1;}
  46. }
  47. fout<<l<<" "<<c;
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement