Uva 232 Crossword Answers

//

看清楚题意再敲还是 原来的blog上的

//

#include<stdio.h>  
#include<string.h>  
#include<stdlib.h>  
#include<math.h>  
char Get_array(char str[101][101],int row)  
{  
    int i;  
    for(i=0;i<row;i++)  
    {  
        gets(str[i]);  
    }  
}  
int main()  
{  
    char str[101][101],Across[1001][1001],Down[1001][1001];  
    int row,line;  
    int count;  
    int x,y;  
    int m,n,p,q;  
    int i,j,I,J;  
    int Begin_x[1000],Begin_y[1000];  
    int res;  
    //res的作用是避免同时加。说不太清楚,写的时候就知道了。  
    int num=0;  
    while(1)  
    {  
        x=0;y=0;  
        m=-1,n=0,p=-1,q=0;  
        count=0;  
        num++;  
        scanf("%d",&row);  
        if(row==0)  
            return 0;  
        scanf("%d",&line);  
        getchar();  
        Get_array(str,row);  
        //二维数组输入  
        for(I=0;I<row;I++)  
        {  
            for(J=0;J<line;J++)  
            {  
                res=0;  
                if(J==0&&str[I][0]!='*')  
                {  
                    res=1;  
                    m++;  
                    count++;  
                    Begin_x[x]=count;  
                    x++;  
                    i=I;j=J;  
                    while(str[i][j]!='*'&&j<line)  
                    {  
                        Across[m][n]=str[i][j];  
                        n++;  
                        j++;  
                    }  
                    n=0;  
                }  
                else if(str[I][J-1]=='*'&&str[I][J]!='*')  
                {  
                    res=1;  
                    m++;  
                    count++;  
                    Begin_x[x]=count;  
                    x++;  
                    i=I;j=J;  
                    while(str[i][j]!='*'&&j<line)  
                    {  
                        Across[m][n]=str[i][j];  
                        n++;  
                        j++;  
                    }  
                    n=0;  
                }  
                if(I==0&&str[0][J]!='*')  
                {  
                    p++;  
                    if(!res)  
                    count++;  
                    Begin_y[y]=count;  
                    y++;  
                    i=I;j=J;  
                    while(str[i][J]!='*'&&i<row)  
                    {  
                        Down[p][q]=str[i][J];  
                        q++;  
                        i++;  
                    }  
                    q=0;  
                }  
                else if(str[I-1][J]=='*'&&str[I][J]!='*')  
                {  
                    p++;  
                    if(!res)  
                    count++;  
                    Begin_y[y]=count;  
                    y++;  
                    i=I;j=J;  
                    while(str[i][j]!='*'&&i<row)  
                    {  
                        Down[p][q]=str[i][J];  
                        q++;  
                        i++;  
                    }  
                    q=0;  
                }  
            }  
        }  
        if(num!=1)  
        {  
            printf("\n");  
        }  
        printf("puzzle #%d:\n",num);  
        printf("Across\n");  
        for(i=0,j=0;i<=m;i++)  
        {  
            printf("%3d.",Begin_x[j]);  
            j++;  
            puts(Across[i]);  
        }  
        printf("Down\n");  
        for(i=0,j=0;i<=p;i++)  
        {  
            printf("%3d.",Begin_y[i]);  
            puts(Down[i]);  
        }  
        memset(str,0,sizeof(str));  
        memset(Across,0,sizeof(Across));  
        memset(Down,0,sizeof(Down));  
        memset(Begin_x,0,sizeof(Begin_x));  
        memset(Begin_y,0,sizeof(Begin_y));  
    }  
    return 0;
}  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值