| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2186 人关注过本帖
标题:请教C语言中关于将二维数组复制到一个三维数组的问题
只看楼主 加入收藏
伯爵瞳
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-12-7
结帖率:0
收藏
 问题点数:0 回复次数:3 
请教C语言中关于将二维数组复制到一个三维数组的问题
小白正在填写一段代码,是有点类似与俄罗斯方块的一段游戏代码,代码如下
要求在增加参数,变量和函数的情况下完成此代码,只能填写// write appropriate codes here.部分。在填到int possible(int m[MR][MC],int b[BR][BC],int pcl[][MR][MC],int pcn)函数部分时,不知道该怎么将二维数组的值复制到一个三维数组中,试了很多次都失败了,所以在此求助各位,帮帮小白

void print(int m[MR][MC]) // EX05
{
   int r,c;

   for(r=0;r<MR;r++)
   {
       for (c=0;c<MC;c++)
       {
           printf("%d ",m[r][c]);
       }
       printf("\n");
   }
}

int equal(int m1[MR][MC],int m2[MR][MC]) // EX06
{
   int r,c;

   for (r=0;r<MR;r++)
       for (c=0;c<MC;c++)
       {
           if(m1[r][c]!=m2[r][c])
                return 0;
       }
       return 1;
}

void reset(int m[MR][MC]) // EX07
{
   int r,c;

   for(r=0;r<MR;r++){
       for(c=0;c<MC;c++){
           m[r][c]=0;
       }
   }
}

void copy(int m1[MR][MC],int m2[MR][MC]) // EX12
{
   int r,c;

   for(r=0;r<ROW;r++)
       for(c=0;c<COL;c++)
           m1[r][c]=m2[r][c];
}

int is_overlap(int m1[MR][MC],int m2[MR][MC]) // EX17
{
   int r,c;

   for (r=0;r<ROW;r++)
       for (c=0;c<COL;c++)
       {
           if(m1[r][c]!=0 && m2[r][c]!=0)
                return 1;
       }
       return 0;
}

int paste(int m[MR][MC],int r0,int c0,int b[BR][BC]) // EX18
{
   int r,c;

   for(r=0;r<BR;r++)
       for(c=0;c<BC;c++){
           if(b[r][c]==1){
               if(r+r0>=0 && c+c0>=0 && r+r0<MR && c+c0<MC)
                   m[r+r0][c+c0]=b[r][c];
               else return 0;
           }
       }
   return 1;
}

int possible(int m[MR][MC],int b[BR][BC],int pcl[][MR][MC],int pcn)
{
   int temp[MR][MC];
   int r,c,i;

   // write appropriate codes here.
   return pcn;
}

int main(void)
{
   int pcl[1000][MR][MC];
   int pcn=0;

   int m[MR][MC] = {
       {1,0,0,1,0,0,0},
       {0,0,0,0,0,0,1},
       {0,1,0,0,0,1,1},
       {0,0,0,0,0,0,1},
       {0,1,0,0,1,0,0},
       {0,1,0,0,0,0,0},
       {0,1,1,0,0,0,0}
   };
   int b[BR][BC] = {
       {0,0,0,0},
       {1,1,1,0},
       {1,0,0,0},
       {0,0,0,0},
   };
   int i;

   pcn=possible(m,b,pcl,pcn);
   for(i=0;i<pcn;++i) {
       printf("possible choice id=%d\n",i);
       print(pcl[i]);
   }
   return 0;
}
最后应该得到的结果如下
possible choice id=0
0 0 0 0 1 1 1
0 0 0 0 1 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=1
0 0 0 0 0 0 0
1 1 1 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=2
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=3
0 0 0 0 0 0 0
0 0 0 1 1 1 0
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=4
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=5
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
1 1 1 0 0 0 0
1 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=6
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 1 1 1 0 0
0 0 1 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=7
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 1 1 0
0 0 0 1 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0

possible choice id=8
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 1 1 0
0 0 0 1 0 0 0

possible choice id=9
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 1 1 1
0 0 0 0 1 0 0
希望大家帮忙谢谢大家
搜索更多相关主题的帖子: 俄罗斯方块 游戏 possible C语言 write 
2011-12-07 16:12
伯爵瞳
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-12-7
收藏
得分:0 
其实不用看代码。。。只是想请教一下怎么将一个二维数组复制到一个三维数组里面
拜托了
2011-12-07 19:09
fightingsss
Rank: 6Rank: 6
等 级:侠之大者
帖 子:97
专家分:471
注 册:2010-11-12
收藏
得分:0 
建议你去看CopyMemory的相关内容,百度上有,直接复制肯定很慢,看了你就会有所收获了。。。
2011-12-07 21:38
伯爵瞳
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-12-7
收藏
得分:0 
哦 谢谢啊
2011-12-07 22:30
快速回复:请教C语言中关于将二维数组复制到一个三维数组的问题
数据加载中...
 
   



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

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