Skip to content

Instantly share code, notes, and snippets.

@KT-Yeh
Last active January 3, 2016 18:49
Show Gist options
  • Save KT-Yeh/8504746 to your computer and use it in GitHub Desktop.
Save KT-Yeh/8504746 to your computer and use it in GitHub Desktop.
#include <cstdio>
using namespace std;
char square[12][12];
void Fill (int n,int i,int j){
char filled = 'A';
bool up,left,right,down;
while (filled <= 'Z'){
if (i-1<0 || square[i-1][j]!=filled) up=1; else up=0;
if (i+1>=n || square[i+1][j]!=filled) down=1; else down=0;
if (j-1<0 || square[i][j-1]!=filled) left=1; else left=0;
if (j+1>=n || square[i][j+1]!=filled) right=1;else right=0;
if (up && down && left && right){
square[i][j] = filled;
printf("%c",filled);
break;
}
else filled += 1;
}
}
int main()
{
int t,n,Case=1;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
gets(square[0]);
for(int i=0;i<n;i++) gets(square[i]);
printf("Case %d:\n",Case++);
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if (square[i][j]!='.')
printf("%c",square[i][j]);
else Fill(n,i,j);
}
printf("\n");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment