UVa-232 Crossword Answers

#include<iostream>
#include<cstdio>
#include<cstring>
#include<ctype.h>
using namespace std;
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    int a,b,pcnt=0;
    while(cin>>a&&a)
    {
        if((++pcnt)>1) printf("\n");
        printf("puzzle #%d:\n",pcnt);
        cin>>b;
        char c[15][15]={};
        int n[15][15]={};
        for(int i=1;i<=a;i++)
            cin>>c[i]+1;
        int cnt=0;
        for(int i=1;i<=a;i++)
            for(int j=1;j<=b;j++)
                if((!isalpha(c[i][j-1])||!isalpha(c[i-1][j]))&&isalpha(c[i][j]))
                    n[i][j]=(++cnt);
        printf("Across\n");
        for(int i=1;i<=a;i++)
            for(int j=1;j<=b;j++)
                if(!isalpha(c[i][j-1])&&isalpha(c[i][j]))
                {
                    printf("%3d.",n[i][j]);
                    for(int k=j;isalpha(c[i][k]);k++)
                        printf("%c",c[i][k]);
                    printf("\n");
                }
        printf("Down\n");
        for(int i=1;i<=a;i++)
            for(int j=1;j<=b;j++)
                if(!isalpha(c[i-1][j])&&isalpha(c[i][j]))
                {
                    printf("%3d.",n[i][j]);
                    for(int k=i;isalpha(c[k][j]);k++)
                        printf("%c",c[k][j]);
                    printf("\n");
                }
    }
}

posted on 2015-02-15 12:31  windrises  阅读(118)  评论(0编辑  收藏  举报

导航