Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <cstring>
- using namespace std;
- int a[103][103];
- int main()
- {
- ifstream fin("traseu2.in");
- ofstream fout("traseu2.out");
- int n,l,c,i,j,ok=0;
- char s[251];
- fin>>n;
- fin>>l>>c;
- for(i=1;i<=n;i++)
- for(j=1;j<=n;j++)
- fin>>a[i][j];
- fin>>s;
- for(i=0;i<strlen(s)&&ok==0;i++)
- {
- if(s[i]=='E'&&a[l][c+1]==0)
- c++;
- if(s[i]=='V'&&a[l][c-1]==0)
- c--;
- if(s[i]=='N'&&a[l-1][c]==0)
- l--;
- if(s[i]=='S'&&a[l+1][c]==0)
- l++;
- if(l>n)
- {
- l--;
- ok=1;
- }
- if(l==0)
- {
- l++;
- ok=1;
- }
- if(c>n)
- {
- c--;
- ok=1;
- }
- if(c==0)
- {c++;
- ok=1;}
- }
- fout<<l<<" "<<c;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement