Pagini recente » Cod sursa (job #857127) | Cod sursa (job #519103) | Cod sursa (job #2661859) | Cod sursa (job #2594226) | Cod sursa (job #601018)
Cod sursa(job #601018)
using namespace std;
#include <fstream>
ifstream fin("rj.in");
ofstream fout("rj.out");
short int dimx,dimy;
char matrice[100][100];
short int pcol[8]={-1,-1,-1,0,1,1,1,0};
short int plin[8]={-1,0,1,1,1,0,-1,-1};
short int i,j,li[2],lj[2];
short int stop,ah,k,uh;
int main()
{
fin>>dimx>>dimy;fin.get();
//////////////////// C I T I R E//////////////
for(i=1; i<=dimx; i++)
fin.getline(matrice[i]+1, 101);
////////////BORDRADE///////////
for(i=0;i<=dimx+1;i++)
matrice[i][0]=matrice[i][dimy+1]='X';
for(j=0;j<=dimy+1;j++)
matrice[0][j]=matrice[dimx+1][j]='X';
k=1;
////////GO GO GO/////////
uh=0;
while(stop!=1)
{
for(i=1;i<=dimx;i++)
for(j=1;j<=dimy;j++)
{
if(matrice[i][j]=='R')
{
if(uh==1||uh==0)
{
for(ah=0;ah<8;ah++)
if(matrice[i+pcol[ah]][j+plin[ah]]!='X')
{
if(matrice[i+pcol[ah]][j+plin[ah]]==' ')
{
matrice[i+pcol[ah]][j+plin[ah]]='R';uh=2;li[1]=i;lj[1]=j;
}
else
if(matrice[i+pcol[ah]][j+plin[ah]]=='J')
{
fout<<k+1<<" "<<i+pcol[ah]<<" "<<j+plin[ah];
return 0;
}
}
}
}
else
if(matrice[i][j]=='J')
{
if(uh==2||uh==0)
{
for(ah=0;ah<8;ah++)
if(matrice[i+pcol[ah]][j+plin[ah]]!='X')
{
uh=1;
if(matrice[i+pcol[ah]][j+plin[ah]]==' ')
{matrice[i+pcol[ah]][j+plin[ah]]='J';uh=2;li[0]=i;lj[0]=j;}
else
if(matrice[i+pcol[ah]][j+plin[ah]]=='R')
{
fout<<k+1<<" "<<i+pcol[ah]<<" "<<j+plin[ah];
return 0;
}
}
}
}
}
if(li[0]==li[1]&&lj[0]==lj[1])
{
fout<<k<<" "<<i+pcol[ah]<<" "<<j+plin[ah];
return 0;
}
k++;
}
}