螺旋矩陣 有內及外 逆時針

2021-07-05 02:14:31 字數 532 閱讀 3454

在搜尋螺旋矩陣時 發現沒有有內及外 逆時針的code 

參考大神們的神作後,修改了一下,得到有內及外的 逆時針 矩陣。

想起那句話:站在巨人的肩膀上

總之,感謝那些無私賜予我們知識的各路神仙。

#include #include #include #includeusing namespace std;

#define n 5

#define m 5

void main()

{int a[n][m];

a[n/2][m/2]=0;

int p=1;

int raw=n/2;

int col=m/2;

for(int o=1;o<=n/2;o++)

{ int k=2*o-1;

int r=n/2+o;

int l=n/2-o;

int t=m/2-o;

int b=m/2+o;

for(int i=0;i

基礎題目 n階蛇形螺旋矩陣的簡單思路 逆時針旋轉

1.今天發現了乙個螺旋矩陣的簡單思路,清晰易懂。2.之下為 均為逆時針旋轉,四個方向 include include include include include include include typedef unsigned long long ll const int inf 1e9 con...

PHP實現順時針列印矩陣及螺旋矩陣的方法

問題輸入乙個矩陣,按照從外向裡以順時針的順序依次列印出每乙個數字,例如,如果輸入如下矩陣 則依次列印出數字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.解決方法 就是一圈一圈地列印,只要控制好迴圈就可以。注意單行單列的情況。實現 function printmatri...

順時針從外到內列印數字矩陣

列印數字矩陣到標準輸出。按順時針方向,從外到內列印矩陣。起點是矩陣的左上角。class matrix def initialize width n 0 width width 矩陣的寬度 建立二維陣列 square array.new width do array.new width,0 enden...