Pagini recente » Cod sursa (job #2926916) | Cod sursa (job #2966339) | Cod sursa (job #2594405) | Cod sursa (job #2121810) | Cod sursa (job #951604)
Cod sursa(job #951604)
#include <fstream>
#include <string.h>
#include <istream>
#include <utility>
#include <deque>
using namespace std;
string aux;
ifstream f("rj.in");
ofstream g("rj.out");
int m,n,mat[101][101];
deque<pair<int,int> > drum;
deque<int> drumb;
int matb[101][101];
int ii[]={-1,0,1,0};
int jj[]={0,1,0,-1};
void Lee()
{
bool ok=true,ook=true;
while(!drum.empty()&&ok)
{
for(int i=0;i<4&&ook;i++)
{
int tempi=drum.back().first+ii[i];
int tempj=drum.back().second+jj[i];
if(tempi>=0&&tempj>=0&&tempi<n&&tempj<m)
{
if(mat[tempi][tempj]==0)
{drum.push_front(make_pair(tempi,tempj));
matb[tempi][tempj]=matb[drum.back().first][drum.back().second];
mat[tempi][tempj]=mat[drum.back().first][drum.back().second]+1;}
if(mat[tempi][tempj]>=mat[drum.back().first][drum.back().second]&&matb[tempi][tempj]+matb[drum.back().first][drum.back().second]==0)
{g<<mat[tempi][tempj]<<' '<<tempi+1<<' '<<tempj+1<<'\n';ok=ook=false;}//deretinutvaloare+coordonate+intrerupere
}
}
drum.pop_back();
}
}
void Print()
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
g<<mat[i][j];
g<<'\n';
}
}
int main()
{
f>>n>>m;
getline(f,aux,'\n');
for(int i=0;i<n;i++)
{
getline(f,aux,'\n');
for(int j=0;j<m;j++)
{
if(aux[j]=='J')
drum.push_front(make_pair(i,j)),matb[i][j]=-1;
else if(aux[j]=='R')
drum.push_front(make_pair(i,j)),matb[i][j]=1;
else{
matb[i][j]=0;
if(aux[j]==' ')
mat[i][j]=0;
if(aux[j]=='X')
mat[i][j]=1;
}
}
}
Lee();
//Print();
f.close();
g.close();
return 0;
}