Răspuns :
Răspuns:
#include<iostream>
#include<fstream>
#include<queue>
using namespace std;
ifstream in("matrixIN.txt");
ofstream out("matrixOUT.txt");
int di[4]= {0,0,1,-1};
int dj[4]= {1,-1,0,0};
int x1,y1,x2,y2,n,m;
int v[1000][1000];
queue<pair<int,int>>coada;
void Read()
{
in>>n>>m;
in>>x1>>y1;
in>>x2>>y2;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++)
in>>v[i][j];
}
bool Ok(int i,int j)
{
if(i<1 || j<1 || i>n || j>n)
return false;
if(v[i][j]==1)
return false;
return true;
}
void Lee()
{
int i,j,i1,j1;
v[x1][y1]=1;
coada.push(make_pair(x1,y1));
while(!coada.empty())
{
i=coada.front().first;
j=coada.front().second;
coada.pop();
for(int directie=0; directie<4; directie++)
{
i1=i+di[directie];
j1=j+dj[directie];
if(Ok(i1,j1) && v[i1][j1]<1)
{
v[i1][j1]=v[i][j]+1;
coada.push(make_pair(i1,j1));
}
}
}
}
int main()
{
Read();
Lee();
cout<<v[x2][y2];
}
Explicație:
eu am denumit altfel fisierele asa ca atunci cand o sa probezi problema
sa schimbi numele fisierelor
si sa treci datele fix in ordinea in care sunt citite infunctia Read