2010年9月17日 星期五

ACM 11520 - Fill the Square

#include <stdio.h>

char square[11][11];
int n;
char ch = 'A';
int isSame(int row, int col, char ch)
{
if (row != 0)
{
if (ch == square[row - 1][col])
return 0;
}
if (row != n)
{
if (ch == square[row + 1][col])
return 0;
}
if (col != 0)
{
if (ch == square[row][col - 1])
return 0;
}
if (col != n)
{
if (ch == square[row][col + 1])
return 0;
}
return 1;
}

int main()
{
int caseNum, i, j, k, t;

scanf("%d", &caseNum);
for (t = 1; t <= caseNum; t++)
{
scanf("%d", &n);
for (i = 0; i < n; i ++)
scanf("%s", square[i]);
printf("Case %d:\n", t);
for (i = 0; i < n; i ++, printf("\n"))
for (j = 0; j < n; j ++)
{
if (square[i][j] != '.')
{
printf("%c", square[i][j]);
continue;
}
else
{
for (k = 0; k < 26; k ++)
if (isSame(i, j, ch + k))
{
printf("%c", ch + k);
square[i][j] = ch + k;
break;
}
}
}
}
return 0;
}


回目錄
回首頁

沒有留言 :

張貼留言

Related Posts Plugin for WordPress, Blogger...