Blocks two-dimensional square arrays into VC code

Source: Internet
Author: User

For example

[1, 2, 3, 4, 5, 6

4, 5, 6, 7, 8, 9

2, 3, 4, 5, 6, 7

3, 4, 5, 6, 7, 8

5, 6, 7, 8, 9, 10

0, 1, 2, 3, 4, 5]

Decomposed into nine small matrices of 2*2

[[[[[[[[[]

]

# Include "iostream"
Using namespace STD;
# Define side_length 2 // specify the length and width of the square matrix.
# Define height 6 // The length of the original matrix
# Define width 6 // width of the original matrix
Void print (int * buffer, int length );
Void main ()
{
Int I, J, K, T;

Int matrix [height] [width] =, }, {, 9, 10 }};
Int * minimatrix;
Int h_num = height/side_length; // number of segments separated by a small matrix in the long and wide directions
Int w_num = width/side_length;

Minimatrix = new int [side_length * side_length];
Cout <"the original matrix is:" <Endl;
For (I = 0; I {
For (j = 0; j <width; j ++)
{
Cout <matrix [I] [J] <"";
}
Cout <Endl;
}
For (I = 0; I {
For (j = 0; j <w_num; j ++)
{
For (k = 0; k <side_length; k ++)
{
For (t = 0; t <side_length; t ++)
{
* (Minimatrix + K * side_length + T) = matrix [I * side_length + k] [J * side_length + T];
 
}

}

Print (minimatrix, side_length); // display the split small matrix.
}
}
}
// Display function
Void print (int * buffer, int length)
{
Int M, N;
Int num = 1;
Cout <num <"minimatrix is:" <Endl;

For (m = 0; m <length; m ++)
{
For (n = 0; n <length; n ++)
{
Cout <* (buffer + M * Length + n) <"";
}
Cout <Endl;
}
Num ++;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.