C++實(shí)現(xiàn)二維數(shù)組(二維矩陣)旋轉(zhuǎn)(多角度)

代碼如下:

    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;
    }
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容