UVA-3.6-纵横字谜-232
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct mark
{
int x;
int y;
int book;
};
int main()
{
char str[15][15];
memset(str,0,sizeof(str));
int m,n;
int count3=1;
while(scanf("%d",&m)!=EOF&&m!=0)
{
int i,j;
memset(str,0,sizeof(str));
scanf("%d",&n);
char space;
space=getchar();
struct mark a[100],b[100];
for(i=1;i<=m;i++)
{
gets(str[i]);
}
int count=0;
int count1=0;
int count2=0;
for(i=1;i<=m;i++)
{
for(j=0;j<n;j++)
{ int mark=1;
if((j-1<0||str[i][j-1]=='*')&&str[i][j]!='*')
{
count++;
count1++;
a[count1].x=i;
a[count1].y=j;
//printf("%d %d***\n",i,j);
a[count1].book=count;
mark=0;
//continue;
}
if((i-1<=0||str[i-1][j]=='*')&&str[i][j]!='*')
{ if(mark)
count++;
count2++;
b[count2].x=i;
b[count2].y=j;
b[count2].book=count;
//continue;
}
}
}
if(count3!=1)
printf("\n");
printf("puzzle #%d:\n",count3);
printf("Across\n");
for(i=1;i<=count1;i++)
{
int x1=a[i].x;
int y1=a[i].y;
printf(" %2d.",a[i].book);
int q;
//printf("x1=%d y1=%d\n",x1,y1);
for(q=y1;str[x1][q]!='*'&&q<n;q++)
{
printf("%c",str[x1][q]);
}
printf("\n");
}
printf("Down\n");
for(i=1;i<=count2;i++)
{
int x1=b[i].x;
int y1=b[i].y;
printf(" %2d.",b[i].book);
int q;
//printf("x1=%d y1=%d\n",x1,y1);
for(q=x1;str[q][y1]!='*'&&q<=m;q++)
{
printf("%c",str[q][y1]);
}
printf("\n");
}
count3++;
}
}