can someone check my code?
Thanks
Code: Select all
#include <stdio.h>
#include <string.h>
char str[35][85];
int train[100];
int index_i;
void Akromon(const int i, const int j){
str[i][j]='#';
if(i-1>=0&&str[i-1][j]==' ') {//printf("diving into:i-1 j\n");
Akromon(i-1,j);}
if(str[i-1][j+1]==' ') {//printf("diving into:i-1 j+1\n");
Akromon(i-1,j+1);}
if(i-1>=0&&j-1>=0&&str[i-1][j-1]==' ') {//printf("diving into:i-1 j-1\n");
Akromon(i-1,j-1);}
if(j-1>=0&&str[i][j-1]==' ') {//printf("diving into:i j-1\n");
Akromon(i,j-1);}
if(str[i][j+1]==' ') {//printf("diving into:i j+1\n");
Akromon(i,j+1);}
if(i+1<=index_i-1&&str[i+1][j]==' ') {//printf("diving into:i+1 j\n");
Akromon(i+1,j);}
if(i+1<=index_i-1&&str[i+1][j+1]==' ') {//printf("diving into:i+1 j+1\n");
Akromon(i+1,j+1);}
if(i+1<=index_i-1&&j-1>=0 && str[i+1][j-1]==' ') {//printf("diving into:i+1 j-1\n");
Akromon(i+1,j-1);}
return;
}
int main(){
int T, t;
while(scanf("%d",&T)==1){
//getchar();
memset(train,0,sizeof(train));
memset(str,'\0',sizeof(str));
for(t=1;t<=T;t++){
index_i=-1;
do{
index_i++;
gets(&str[index_i][0]);
train[index_i]=strlen(&str[index_i][0]);
}while(str[index_i][0]!='_');
for(int i=0; i<index_i;i++){
for(int j=0;j<train[i];j++){
if(str[i][j]=='*')
Akromon(i,j);
}
}
for(int i=0; i<index_i;i++){
for(int j=0;j<train[i];j++)
printf("%c",str[i][j]);
printf("\n");
}
}
}
return 0;
}