Take input as a string

if u take input as character by character then it may cause input/output difficulties. Let,

char A [10] [11] // 2-D character array

scanf (“%s”, A [0]); // this will take input as string, save it in 0 indexed row (means, first row) and use sufficient column

Traverse each cell and check the possibilities of every character starting from A to Z. As soon as, a character will pass the possibilities then insert the character instead of empty cell, represented by a dot (.)

Let, Index starts from 1 to N, and A [10] [11] is a 2-D array

Suppose, we r checking a character C, whether it is appropriate, for a particular cell, A [Row] [Column]

if A [Row] [Column – 1] not equals to C and

A [Row – 1] [Column] not equals to C and

A [Row] [Column + 1] not equals to C and

A [Row + 1] [Column] not equals to C then

A [Row] [Column] must be assigned with C

Critical input:

2

5

..ABC

ABC..

ERWK.

…AB

EA…

4

..A.

A..A

.A..

A.A.

Critical output:

Case 1:

BCABC

ABCAB

ERWKA

ABCAB

EABCA

Case 2:

BCAB

ABCA

BABC

ABAB

#include <stdio.h>
long N;
char A[11][11];
int Check (long I, long J, long C)
{
if (A[I][J-1]==C || A[I-1][J]==C || A[I][J+1]==C || A[I+1][J]==C)
return 0;
return 1;
}
int main ()
{
//freopen ("11520out", "w", stdout);
long T, I, J, C, Flag, Case=0;
scanf ("%ld", &T);
while (T){
scanf("%ld", &N);
for (I=0; I<N; I++)
scanf("%s", A[I]);
printf("Case %ld:\n", ++Case);
for (I=0; I<N; I++){
for (J=0; J<N; J++){
Flag = 0;
if (A[I][J]=='.'){
for (C=65; Flag==0; C++){
if (Check (I, J, C)){
A[I][J] = C;
Flag = 1;
}
}
}
}
}
for (I = 0; I<N; I++){
for (J=0; J<N; J++)
printf("%c", A[I][J]);
printf("\n");
}
T--;
}
return 0;
}

### Like this:

Like Loading...

*Related*

## Published by Shahab

Completed B.Sc in CSE, @United International University, Dhaka.
Currently working as Development Engineer, Android and iOS Application.
View all posts by Shahab

The checking part is easy. But how’ll I place the letters?

different Abul chooses different process to accomplish an identical task.

its totally ur choice to select ur own path. Not necessary it should be similar to mine

got my point ?

hope not !