題目連結: https://zerojudge.tw/ShowProblem?problemid=b965

# 程式碼

#include <iostream>
#include <cstring>
#include <stack>
using namespace std;
int arr[11][11], tmp[11][11];
int r, c, m,x;
void rFlip(){
    for ( int i=1; i<=r; ++i )
        for ( int j=1; j<=c; ++j )
            arr[r-i+1][j] = tmp[i][j];
}
void rRotate(){
    for ( int j=1; j<=c; ++j )
        for ( int i=1; i<=r; ++i )
            arr[c-j+1][i] = tmp[i][j];
    swap(r,c);
}
int main() {
	while ( cin >> r >> c >> m ) {
        memset(arr,0,sizeof(arr));
		for (int i=1; i<=r; ++i )
			for (int j=1; j<=c; ++j )
				cin >> arr[i][j];
        stack<int>st;
		for (int i=0; i<m; i++ ){
			cin>>x;
			st.push(x);
		}
		while(!st.empty()){
            x = st.top() , st.pop();
			memcpy(&tmp,&arr,sizeof(arr));
			if ( x==0 ) rRotate();
            else rFlip();
		}
		cout << r << ' ' << c << '\n';
		for ( int i=1; i<=r; ++i ) {
			for ( int j=1; j<=c; ++j ) {
				if ( j > 1 )	cout << ' ';
				cout << arr[i][j];
			}
			cout << '\n';
		}
	}
	return 0;
}
更新於 閱讀次數

用實際行動犒賞爆肝的我😀

Zrn Ye LinePay

LinePay