代碼如下:
int xy = 3; //二維數(shù)組元素個(gè)數(shù),此處設(shè)定xy軸元素個(gè)數(shù)一致,即一級(jí)數(shù)組與二級(jí)數(shù)組元素個(gè)數(shù)一致
int n = xy-1; //數(shù)組索引極限值,用之進(jìn)行索引運(yùn)算操作
int src[xy][xy],dst[xy][xy],dst1[xy][xy],dst2[xy][xy];
uniform_int_distribution<unsigned> u(0,20); //隨機(jī)數(shù)分布類(lèi)型
default_random_engine e; //隨機(jī)數(shù)引擎
/*為source數(shù)組充實(shí)數(shù)據(jù)*/
for(int i = 0 ; i < xy ; ++i)
{
for(int j = 0 ; j < xy ; ++j)
{
src[i][j] = u(e);
cout<<src[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
/*轉(zhuǎn)180*/
for(int i = 0 ; i < xy ; ++i)
{
for(int j = 0 ; j < xy ; ++j)
{
dst[i][j] = src[n-i][n-j];
cout<<dst[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
/*順時(shí)針轉(zhuǎn)90*/
for(int i = 0 ; i < xy ; ++i)
{
for(int j = 0 ; j < xy ; ++j)
{
dst1[i][j] = src[n-j][i];
cout<<dst1[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
/*逆時(shí)針轉(zhuǎn)90*/
for(int i = 0 ; i < xy ; ++i)
{
for(int j = 0 ; j < xy ; ++j)
{
dst2[i][j] = src[j][n-i];
cout<<dst2[i][j]<<" ";
}
cout<<endl;
}