Pagini recente » Cod sursa (job #2752637) | Cod sursa (job #1826918) | Probleme de Taietura | Cod sursa (job #580042) | Cod sursa (job #385024)
Cod sursa(job #385024)
#include<stdio.h>
#include<fstream>
using namespace std;
FILE *f;
struct cuvant{int x,y;}c[20000];
int n,m,i,j,ic=1,sc=0,a[105][105],lun,xx,yy;
char cc,linie[105];
void lant(int x,int y)
{
while(ic<=sc)
{
if(a[x-1][y-1]==a[x][y]+1)
{lun=a[x][y]+1;xx=x-1;yy=y-1;break;}
else
if(a[x-1][y-1]==0&&x-1>=1&&y-1>=1)
{sc++;
c[sc].x=x-1;
c[sc].y=y-1;
a[x-1][y-1]=a[x][y]+1;}
if(a[x-1][y]==a[x][y]+1)
{lun=a[x][y]+1;xx=x-1;yy=y;break;}
else
if(a[x-1][y]==0&&x-1>=1)
{sc++;
c[sc].x=x-1;
c[sc].y=y;
a[x-1][y]=a[x][y]+1;}
if(a[x-1][y+1]==a[x][y]+1)
{lun=a[x][y]+1;xx=x-1;yy=y+1;break;}
else
if(a[x-1][y+1]==0&&x-1>=1&&y+1<=m)
{sc++;
c[sc].x=x-1;
c[sc].y=y+1;
a[x-1][y+1]=a[x][y]+1;}
if(a[x][y-1]==a[x][y]+1)
{lun=a[x][y]+1;xx=x;yy=y-1;break;}
else
if(a[x][y-1]==0&&y-1>=1)
{sc++;
c[sc].x=x;
c[sc].y=y-1;
a[x][y-1]=a[x][y]+1;}
if(a[x+1][y-1]==a[x][y]+1)
{lun=a[x][y]+1;xx=x+1;yy=y-1;break;}
else
if(a[x+1][y-1]==0&&x+1<=n&&y-1>=1)
{sc++;
c[sc].x=x+1;
c[sc].y=y-1;
a[x+1][y-1]=a[x][y]+1;}
if(a[x+1][y]==a[x][y]+1)
{lun=a[x][y]+1;xx=x+1;yy=y;break;}
else
if(a[x+1][y]==0&&x+1<=n)
{sc++;
c[sc].x=x+1;
c[sc].y=y;
a[x+1][y]=a[x][y]+1;}
if(a[x+1][y+1]==a[x][y]+1)
{lun=a[x][y]+1;xx=x+1;yy=y+1;break;}
else
if(a[x+1][y+1]==0&&x+1<=n&&y+1<=m)
{sc++;
c[sc].x=x+1;
c[sc].y=y+1;
a[x+1][y+1]=a[x][y]+1;}
if(a[x][y+1]==a[x][y]+1)
{lun=a[x][y]+1;xx=x;yy=y+1;break;}
else
if(a[x][y+1]==0&&y<=m)
{sc++;
c[sc].x=x;
c[sc].y=y+1;
a[x][y+1]=a[x][y]+1;}
ic++;
lant(c[ic].x,c[ic].y);
}
}
int main()
{
f=fopen("rj.in","r");
ifstream ff("rj.in");
ofstream g("rj.out");
ff>>n>>m;
fgets(linie,100,f);
for(i=1;i<=n;i++)
{fgets(linie,100,f);
for(j=0;j<m;j++)
{cc=linie[j];
if(cc=='X')
a[i][j+1]=-1;
else
if(cc=='R'||cc=='J')
{ a[i][j+1]=1;
sc++;
c[sc].x=i;
c[sc].y=j+1;
}
}}
lant(c[ic].x,c[ic].y);
g<<lun<<" "<<xx<<" "<<yy;
ff.close();
g.close();
return 0;}