C ++将数组拆分成块 [英] C++ split array into blocks

查看:105
本文介绍了C ++将数组拆分成块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我怎么能把一个数组拆分成块。例如给定一个大小为4x4的数组将数组除以2x2的块,然后数组的大小为4x4,这样就会有四个2x2的块。 />


在这种情况下,块大小为2;



Hello every one how can i split an array into blocks.For example Given an array of size 4x4 divide the array by blocks of 2x2 and then the size of the array is 4x4 so there will be four blocks of 2x2.

In this case block size is 2;

             Block 1      Block2
0 1 0 0       0 1         0 0
1 1 1 0 - >   1 1         1 0
0 0 0 0 - >
1 1 0 0       Block 3      Block4
              0 0          0 0
              1 1          0 0



我想要这样的东西。任何帮助将不胜感激



我尝试过:



其实我无法做到,因为我无法找到任何想法


I want something like this. Any help would be appreciated

What I have tried:

Actually i could not make it because i couldn't have find any idea

推荐答案

怎么样:



How about:

int block[4][4] =
{
    { 0,1,0,0 },
    { 1,1,1,0 },
    { 0,0,0,0 },
    { 1,1,0,0 }
};

int block1[2][2];
int block2[2][2];
int block3[2][2];
int block4[2][2];

for (int i = 0; i < 2; i++)
{
    for (int j = 0; j < 2; j++)
    {
        block1[i][j] = block[i][j];
        block2[i][j] = block[i][j+2];
        block3[i][j] = block[i+2][j];
        block4[i][j] = block[i+2][j+2];
    }
}


这篇关于C ++将数组拆分成块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆