| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 730 人关注过本帖
标题:海龟作图 请帮忙找错...头都炸了...
只看楼主 加入收藏
寂寞的天空
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-12-22
收藏
 问题点数:0 回复次数:4 
海龟作图 请帮忙找错...头都炸了...
设想有一只机械海龟,它在c语言的控制下在屋里四处爬行。海龟拿了一支笔,这只笔或朝      
    上或朝下,当笔朝下时,海龟用笔画下自己的轨迹,当笔朝上时,海龟在移动过程中什么也不画。      
    使用一个50x50的数组,并把数组初始化为0。从一个装有命令的数组中读取各种命令。不      
    管是笔朝上还是笔朝下,都要跟踪海龟的当前位置。假定海龟总是从地板上(0,0)出发      
    ,并且开始时笔是朝上的。程序必须处理的一组命令如下:      
    命令                                                       含义      
    1                                                                   笔朝上      
    2                                                                   笔朝下      
    3                                                                   右转弯      
    4                                                                   左转弯      
    5,10                                                   向前走10格(或其他的格数)      
    6                                                                   打印50x50的数组      
    9                                                                   数据结束(标记)  
我写的:
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int array[50][50];
    int cmd[20];
   
    int i, penup=0, turn=1, x=0, y=0, m=0, n=0;
   
   for(i=0;i<=19;i++)
   cmd[i]=0;
   for(x=0;x<=49;x++)
   for(y=0;y<=49;y++)
   array[x][y]=0;
   
   for(i=0;i<=19;i++)  /*输入移动命令*/
   {
    scanf("%d",&cmd[i]);
     if(cmd[i]==9)
      break;
    }
i=0;     
while(cmd[i]!=9){
    switch(cmd[i]){
                      case 1: penup=0;
                      case 2: penup=1;
                      case 3: (turn-1)%4;
                      case 4: (turn+1)%4;
                      case 5: scanf("%d",&m);
                              switch(turn){
                                            case 0: for(;n<=m;x--,n++)/*up*/
                                                       {
                                                       if(penup==1)
                                                       array[x][y]=1;                                                        
                                                       }
                                                       n=0
                                                       ;
                                            case 1: for(;n<=m;y++,n++)/*right*/
                                                      {
                                                      if(penup==1)
                                                      array[x][y]=1;
                                                      }
                                                      n=0;                                          
                                            case 2: for(;n<=m;x++,n++)/*down*/
                                                      {
                                                      if(penup==1)
                                                      array[x][y]=1;
                                                      }
                                                      n=0;
                                            case 4: for(;n<=m;y--,n++)/*left*/
                                                      {
                                                      if(penup==1)
                                                      array[x][y]=1;
                                                      }
                                                      n=0;
                                            }
                      case 6: for(x=0;x<=49;x++)
                                for(y=0;y<=49;y++)
                                {
                                 if(array[x][y]==1)               
                                 printf("*");
                                 else
                                 printf(" ");
                                 
                                 if((y+1)%50==0)
                                 printf("\n");
                                 }
                      }
                      ++i;
}

 system("pause");
 return 0;
}
搜索更多相关主题的帖子: 海龟 
2008-04-12 19:45
寂寞的天空
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-12-22
收藏
得分:0 
没人帮忙么?
2008-04-13 13:50
flamelaird
Rank: 1
来 自:广东佛山
等 级:新手上路
帖 子:21
专家分:0
注 册:2008-3-26
收藏
得分:0 
在看在看!! 慢慢来 !有点长!
2008-04-13 16:15
寂寞的天空
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-12-22
收藏
得分:0 
加油啊~再来点人帮忙看看吧,谢谢了...
快晕了...
2008-04-14 22:04
303770957
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:小飞侠
威 望:6
帖 子:838
专家分:2125
注 册:2005-9-10
收藏
得分:0 
有时间了看!

♂ 死后定当长眠,生前何须久睡。♀
2008-04-14 22:32
快速回复:海龟作图 请帮忙找错...头都炸了...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057635 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved