UVa 232:Crossword Answers

#include <stdio.h>

int main()
{
    char puzzle[12][12];
    int r, c, i, ct = 0;
    while(1 == scanf("%d", &r) && r && 1 == scanf("%d", &c))
    {
        while(getchar() != '\n');
        for(i = 0; i < r; ++i)
            gets(puzzle[i]);
        if(ct) putchar('\n');
        printf("puzzle #%d:\n", ++ct);
        printf("Across\n");
        int x, y, num = 0;
        for(x = 0; x < r; ++x)
        {
            for(y = 0; y < c; ++y)
            {
                if((puzzle[x][y] != '*') && (y - 1 < 0 || x - 1 < 0 || puzzle[x][y-1] == '*' || puzzle[x-1][y] == '*'))
                    ++num;
                if(puzzle[x][y] != '*' && (y - 1 < 0 || puzzle[x][y-1] == '*'))
                {
                    printf("%3d.", num);
                    int t = y;
                    while(t < c && puzzle[x][t] != '*')
                        putchar(puzzle[x][t++]);
                    putchar('\n');
                }
            }
        }
        num = 0; printf("Down\n");
        for(x = 0; x < r; ++x)
        {
            for(y = 0; y < c; ++y)
            {
                if((puzzle[x][y] != '*') && (y - 1 < 0 || x - 1 < 0 || puzzle[x][y-1] == '*' || puzzle[x-1][y] == '*'))
                    ++num;
                if(puzzle[x][y] != '*' && (x - 1 < 0 || puzzle[x-1][y] == '*'))
                {
                    printf("%3d.", num);
                    int t = x;
                    while(t < r && puzzle[t][y] != '*')
                        putchar(puzzle[t++][y]);
                    putchar('\n');
                }
            }
        }
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值