Pagini recente » Cod sursa (job #2659561) | Cod sursa (job #269000) | Cod sursa (job #2229685) | Cod sursa (job #130927) | Cod sursa (job #601010)
Cod sursa(job #601010)
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;
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=0;
////////GO GO GO/////////
uh=0;
while(stop!=1)
{
k++;
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;
}
else
if(matrice[i+pcol[ah]][j+plin[ah]]=='J')
{
fout<<k<<" "<<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;}
else
if(matrice[i+pcol[ah]][j+plin[ah]]=='R')
{
fout<<k<<" "<<i+pcol[ah]<<" "<<j+plin[ah];
return 0;
}
}
}
}
}
}
}