#include <iostream>#include<iomanip>using namespacestd;#defineSIZE 8intMainintargcChar**Argv[]) { intmatrix[size][size] = {0}; inta[size][size] = {0 }; int*p =nullptr; P= &matrix[0][0]; //Initialize Matrix for(intK =0; K < size*size; k++) { *p++ =k; } //Print the original matrixcout <<"the original matrix is as Follows:"<<endl; for(intk=0; k < size;k++) { for(inth =0; H < size;h++) {cout<< SETW (4) << * (* (matrix + k) +h); } cout<<endl; } //z-shaped Orchestration inti =0, j =0;//variable cannot be duplicated for(intx =0; X < size;x++) { for(inty =0; Y < size;y++) { * (* (a + i) + j) = * (* (matrix + x) +y); if((i==size-1|| i==0) &&j%2==0)//move horizontally Right{j++; Continue; } if((j==0|| j==size-1) &&i%2==1)//Move Down vertically{i++; Continue; } if((i+j)%2==0)//top Right{i--; J++; } Else if((i+j)%2==1)//Lower left{i++; J--; } }} cout<< Endl <<"The matrix after the z-shaped arrangement is as Follows:"<<endl; for(inti =0; I < size;i++) { for(intj =0; J < size;j++) {cout<< SETW (4) << * (* (a + i) +j); } cout<<endl; } return 0;}
Operation Result:
the original matrix is as Follows:0 1 2 3 4 5 6 7 8 9 Ten one a - - the - - - + - + a at - - - - - in - to + - the * $ Panax Notoginseng - the + a the + - $ $ - - the - Wuyi the - wu - about $ - - - a + theThe matrix after the z-shaped arrangement is as Follows:0 1 5 6 - the - - 2 4 7 - - - in the 3 8 a - - - a + 9 one - - to + - - Ten + at + the $ the wu - a - - $ Wuyi - - + the Panax Notoginseng - - about - a * $ - the $ - + thePlease press any key to continue ...
The beauty of algorithm--1. Monte Carlo method for calculating pi