Uriel's Corner

Research Associate @ Harvard University / Research Interests: Computer Vision, Biomedical Image Analysis, Machine Learning
posts - 0, comments - 50, trackbacks - 0, articles - 594

POJ 1888 Crossword Answers---模拟

Posted on 2009-09-03 01:48 Uriel 阅读(305) 评论(0)  编辑 收藏 引用 所属分类: POJ模拟
模拟英语填字游戏。。关于序号处理丢了几天突然想到。。
最近这类模拟做了很多。。纪念下~
/*Problem: 1888  User: Uriel 
   Memory: 292K  Time: 32MS 
   Language: C++  Result: Accepted
*/
 

#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>

int g,i,j,a,b,k,x,y,syl;
char str[20][20];

struct M{
    
char r[20];
    
char c[20];
    
int num;
    
int flag1;
    
int flag2;
}
S[2000];

int main()
{
    g
=1;
    
while(1)
    
{
        scanf(
"%d",&a);
        
if(a==0)break;
        scanf(
"%d",&b);
        
for(i=0;i<a;i++)
        
{
            getchar();
            
for(j=0;j<b;j++)
            
{
                scanf(
"%c",&str[i][j]);
            }

        }

        x
=1;
        S[
1].flag1=0;
        S[
1].flag2=0;
        memset(S,
0x00,sizeof(S));
        
for(i=0;i<a;i++)
        
{
            
for(j=0;j<b;j++)
            
{
                syl
=0;
                
if((j==0 || str[i][j-1]=='*'&& str[i][j]!='*')
                
{
                    syl
=1;
                    S[x].num
=x;
                    S[x].flag1
=1;
                    y
=0;
                    
for(k=j;k<b;k++)
                    
{
                        
if(str[i][k]=='*')break;
                        S[x].r[y
++]=str[i][k];
                    }

                }

                
if((i==0 || str[i-1][j]=='*'&& str[i][j]!='*')
                
{
                    syl
=1;
                    S[x].num
=x;
                    S[x].flag2
=1;
                    y
=0;
                    
for(k=i;k<a;k++)
                    
{
                        
if(str[k][j]=='*')break;
                        S[x].c[y
++]=str[k][j];
                    }

                }

                
if(syl)
                
{
                    x
++;
                    S[x].flag1
=0;
                    S[x].flag2
=0;
                }

            }

        }

        printf(
"puzzle #%d:\n",g++);
        printf(
"Across\n");
        
for(i=0;i<x;i++)
        
{
            
if(S[i].flag1==1)
            
{
                printf(
"%3d.%s\n",S[i].num,S[i].r);
            }

        }

        printf(
"Down\n");
        
for(i=0;i<x;i++)
        
{
            
if(S[i].flag2==1)
            
{
                printf(
"%3d.%s\n",S[i].num,S[i].c);
            }

        }

        printf(
"\n");
    }

    system(
"PAUSE");
    
return 0;
}


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理