想法
旋轉逆向回去 是向左旋轉 = 轉置矩陣 + 上下翻轉
翻轉 是上下互換
供參考 看到 用vector的 解法很快 可惜還不懂使用
#include <iostream>
using namespace std;
int a[10][10];
int b[10][10];
void rotate(int r ,int c){
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
b[j][i]=a[i][j];
}
}
for(int i=0;i<c;i++){
for(int j=0;j<r;j++){
a[i][j]=b[i][j];
}
}
for(int i=0;i<c;i++){
for(int j=0;j<r;j++){
b[i][j]=a[c-i-1][j];
}
}
for(int i=0;i<c;i++){
for(int j=0;j<r;j++){
a[i][j]=b[i][j];
}
}
}
void updown(int r,int c){
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
b[i][j]=a[r-i-1][j];
}
}
for(int i=0;i<r;i++){
for(int j=0;j<c;j++){
a[i][j]=b[i][j];
}
}
}
int main(){
int R,C,M;
int tmp;
int op[10];
while(cin>>R>>C>>M){
for(int i=0;i<R;i++){
for(int j=0;j<C;j++){
cin>>a[i][j];
}
}
for(int k=0;k<M;k++){
cin>>op[k];
}
for(int k=M-1;k>=0;k--){
if(op[k]==0){
rotate(R,C);
tmp=R;
R=C;
C=tmp;
}
else {
updown(R,C);
}
}