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 2122 Japan Plotter Driver---模拟

Posted on 2010-02-06 03:59 Uriel 阅读(299) 评论(0)  编辑 收藏 引用 所属分类: POJ模拟
        其实是个简单的模拟,不过做的人很少。。莫非是因为题目长?。。
        跟着队长的脚步A此题。。刚想交PKU挂了。。去百练交之。。结果WA四次。。
        题目倒没什么trick,WA都是自己不细心。。
        总结下要注意的:1.不要出界; 2.case后空行; 3*,+的使用;
        队长3000+B,我去掉注释5000+B。。PF啊。。
        我的ws代码。。懒得简化了。。
/*Problem: 2122  User: Uriel 
   Memory: 176K  Time: 0MS 
   Language: C++  Result: Accepted
*/
 
#include
<stdio.h>
#include
<stdlib.h>
#include
<algorithm>
using namespace std;

int X,Y,x,y,xx,yy;
char pic[100][100],str[100],text[100];

bool ok(int a,int b)
{
    
if(a>0 && a<=&& b>0 && b<=Y)return true;
    
return false;
}


int main()
{
    
int i,j,a,b,c,d;
    
while(scanf("%d %d",&Y,&X),X,Y)
    
{
        
for(i=1;i<=X;i++)
        
{
            
for(j=1;j<=Y;j++)
            
{
                pic[i][j]
=' ';
            }

        }

        
for(i=1;i<=Y;i++)
        
{
            pic[
0][i]='-';
            pic[X
+1][i]='-';
        }

        
for(i=1;i<=X;i++)
        
{
            pic[i][
0]='|';
            pic[i][Y
+1]='|';
        }

        pic[
0][0]='+';
        pic[
0][Y+1]='+';
        pic[X
+1][0]='+';
        pic[X
+1][Y+1]='+';
        
while(1)
        
{
            getchar();
            scanf(
"%s",str);
            
if(strcmp(str,"PRINT")==0)break;
            
else if(strcmp(str,"POINT")==0)
            
{
                scanf(
"%d %d",&y,&x);
                
if(pic[x][y]=='o');
                
else if(pic[x][y]!=' ' && ok(x,y))pic[x][y]='*';
                
else if(ok(x,y))
                    pic[x][y]
='o';
            }

            
else if(strcmp(str,"CLEAR")==0)
            
{
                scanf(
"%d %d %d %d",&a,&b,&c,&d);
                x
=min(b,d);
                xx
=max(b,d);
                y
=min(a,c);
                yy
=max(a,c);
                
for(i=x;i<=xx;i++)
                
{
                    
for(j=y;j<=yy;j++)
                    
{
                        
if(ok(i,j))pic[i][j]=' ';
                    }

                }

            }

            
else if(strcmp(str,"LINE")==0)
            
{
                scanf(
"%d %d %d %d",&a,&b,&c,&d);
                
if(a==c)//----------------------------------vertical
                {
                    y
=min(b,d);
                    yy
=max(b,d);
                    
for(i=y;i<=yy;i++)
                    
{
                        
if(ok(i,a))
                        
{
                            
if(pic[i][a]=='-')pic[i][a]='+';
                            
else if(pic[i][a]=='|' || pic[i][a]=='+');
                            
else if(pic[i][a]!=' ')pic[i][a]='*';
                            
else 
                                pic[i][a]
='|';
                        }

                    }

                }

                
else if(b==d)//----------------------------------horizonal
                {
                    x
=min(a,c);
                    xx
=max(a,c);;
                    
for(i=x;i<=xx;i++)
                    
{
                        
if(ok(b,i))
                        
{
                            
if(pic[b][i]=='|')pic[b][i]='+';
                            
else if(pic[b][i]=='-' || pic[b][i]=='+');
                            
else if(pic[b][i]!=' ')pic[b][i]='*';
                            
else
                                pic[b][i]
='-';
                        }

                    }

                }

                
else if((a<&& b<d) || (a>&& b>d))//---------'\'
                {
                    x
=min(b,d);
                    xx
=max(b,d);
                    y
=min(a,c);
                    yy
=max(a,c);
                    j
=y;
                    
for(i=x;i<=xx;i++,j++)
                    
{
                        
if(ok(i,j))
                        
{
                            
if(pic[i][j]=='/')pic[i][j]='x';
                            
else if(pic[i][j]=='\\' || pic[i][j]=='x');
                            
else if(pic[i][j]!=' ')pic[i][j]='*';
                            
else
                                pic[i][j]
='\\';
                        }

                    }

                }

                
else//------------------------------------------'/'
                {
                    x
=min(b,d);
                    xx
=max(b,d);
                    y
=min(a,c);
                    yy
=max(a,c);
                    j
=yy;
                    
for(i=x;i<=xx;i++,j--)
                    
{
                        
if(ok(i,j))
                        
{
                            
if(pic[i][j]=='\\')pic[i][j]='x';
                            
else if(pic[i][j]=='/' || pic[i][j]=='x');
                            
else if(pic[i][j]!=' ')pic[i][j]='*';
                            
else
                                pic[i][j]
='/';
                        }

                    }

                }

            }

            
else if(strcmp(str,"TEXT")==0)
            
{
                scanf(
"%d %d",&y,&x);
                getchar();
                scanf(
"%s",text);
                
for(i=y;i<strlen(text)+y;i++)
                
{
                    
if(ok(x,i))
                    
{
                        
if(pic[x][i]==' ' || pic[x][i]==text[i-y])pic[x][i]=text[i-y];
                        
else
                            pic[x][i]
='*';
                    }

                }

            }

        }

        
for(i=0;i<=X+1;i++)
        
{
            
for(j=0;j<=Y+1;j++)
            
{
                printf(
"%c",pic[i][j]);
            }

            printf(
"\n");
        }

        printf(
"\n");
    }

//    system("PAUSE");
    return 0;
}



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