旋轉矩陣
代碼如下:
1 #include <iostream>
2 using namespace std; 3 int main() 4 { 5 char a[3][3]; 6 for(int i=0;i<3;i++){ //雙重循環遍歷數組,為數組元素賦值 7 for(int j=0;j<3;j++){ 8 cin>>a[i][j]; 9 } 10 cout<<endl; 11 } 12 for(int j=2;j>=0;j--){ //這里i,j的賦值等相關的東西是通過旋轉前后兩個數組小標進行計算出來的 13 for(int i=0;i<3;i++){ 14 cout<<a[i][j]<<" "; 15 } 16 cout<<endl; 17 } 18 return 0; 19 }
分析與總結:
1、關鍵點是找到變換前后數組下標的變換規律。
寫在最后:
哪里有不足或者錯誤的地方,歡迎小伙伴們進行指教,一起進步哦!