UVA - 11520 Fill the Square

Input
The first line of input will contain an integer that will determine the number of test cases. Each case
starts with an integer n (n ≤ 10), that represents the dimension of the grid. The next n lines will
contain n characters each. Every cell of the grid is either a ‘.’ or a letter from [A, Z]. Here a ‘.’
represents an empty cell.
Output
For each case, first output ‘Case #:’ (# replaced by case number) and in the next n lines output the
input matrix with the empty cells filled heeding the rules above.
Sample Input
2
3
...
...
...
3
...
A..
...
Sample Output
Case 1:
ABA
BAB
ABA
Case 2:
BAB
ABA
BAB

 

遍历就好了。

#include <cstdio>

#define FOR(I, F, N) for(I=F;I<=N;I++) //这个不好调试

const int N = 10 + 2;
int A[N][N] = {0};

int main() {
    int T, n, i, j, c;
    scanf("%d", &T);
    for (int base = 1; base <= T; ++base) {
        scanf("%d", &n);
        getchar(); //坑爹的回车呀
        FOR(i, 1, N - 2)FOR(j, 1, N - 2)A[i][j] = 0; //归零
        FOR(i, 1, n) {
            FOR(j, 1, n)scanf("%c", A[i] + j);  //实际上可用scanf("%s")存入数组
            getchar();
        }
        FOR(i, 1, n) FOR(j, 1, n)if (A[i][j] == '.')
                    FOR(c, 'A', 'Z')
                        if (A[i - 1][j] != c && A[i + 1][j] != c && A[i][j - 1] != c && A[i][j + 1] != c) {
                            A[i][j] = c;
                            break;
                        }
        printf("Case %d:\n", base);
        FOR(i, 1, n) {
            FOR(j, 1, n)printf("%c", A[i][j]);
            printf("\n");
        }
    }
}

 

转载于:https://www.cnblogs.com/wangsong/p/7583559.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值