#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char arr[10][11];
int getPath(int start,int end);
int Pass(int pos);
int nextpos(int curpos);
int main()
{
int i,j;
int start,end;
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
arr[i][j]=getchar();
getchar();
}
for(i=0;i<10;i++)
for(j=0;j<10;j++)
{
if(arr[i][j]=='S')
start=i*10+j;
else if(arr[i][j]=='E')
end=i*10+j;
}
if(getPath(start,end))
{
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
putchar(arr[i][j]);
printf("\n");
}
}
else
{
printf("ERROR!");
}
return 0;
}
int getPath(int start,int end)
{
int S[100],top=-1;
int curpos;
int x,y;
curpos=start;
do
{
x=curpos/10;
y=curpos%10;
arr[x][y]='*';
if(curpos==end)
return 1;
S[++top]=curpos;
while(!(curpos=nextpos(curpos))&&top!=-1)
{
curpos=S[top--];
x=curpos/10;
y=curpos%10;
arr[x][y]='!';
curpos=S[top];
}
}while(top!=-1);
return 0;
}
int Pass(int curpos)
{
int x,y;
x=curpos/10;
y=curpos%10;
if(arr[x][y]==' '||arr[x][y]=='S'||arr[x][y]=='E')
return 1;
else
return 0;
}
int nextpos(int curpos)
{
int i,j,newpos;
i=curpos/10;
j=curpos%10;
if(j+1<10)
{
newpos=curpos+1;
if(Pass(newpos))
{
return newpos;
}
}
if(i+1<10)
{
newpos=curpos+10;
if(Pass(newpos))
return newpos;
}
if(j-1>=0)
{
newpos=curpos-1;
if(Pass(newpos))
return newpos;
}
if(i-1>=0)
{
newpos=curpos-10;
if(Pass(newpos))
return newpos;
}
return 0;
}
/**************************************************************
Problem: 2144
User: admin
Language: C
Result: Accepted
Time:8 ms
Memory:1040 kb
****************************************************************/