10 条题解

  • 15
    @ 2025-1-25 9:14:41
    #include <iomanip>
    #include <iostream>
    #include <cmath> 
    #include <cstring>
    using namespace std; 
    const int N = 1e2 + 10; 
    const int INF = 0x3f3f3f3f;
    
    int n , m , a[N][N] , ans[N][N] , x;
    
    int main() {
    	cin >> n >> m;
    	for(int i = 1; i <= n; i++) {
    		for(int j = 1; j <= n; j++) cin >> a[i][j];
    	}
    
    //操作m次
    	while( m-- ) {
    		cin >> x;//表示当前操作
    
    		if( x == 1) { //最上面一行平移到最下面
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					if(i != 1)
    						ans[i - 1][j] = a[i][j];
    					else
    						ans[n][j] = a[i][j];
    				}
    			}
    
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++)
    					cout << a[i][j] << " ";
    				cout << endl;
    			}
    		} else if( x == 2) {
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					if(i != n)
    						ans[i + 1][j] = a[i][j];
    					else
    						ans[1][j] = a[i][j];
    				}
    			}
    
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++)
    					cout << a[i][j] << " ";
    				cout << endl;
    			}
    		} else if( x == 3) {
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					if(j != 1)
    						ans[i][j - 1] = a[i][j];
    					else
    						ans[i][n] = a[i][j];
    				}
    			}
    
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++)
    					cout << a[i][j] << " ";
    				cout << endl;
    			}
    		} else if( x == 4) {
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					if(j != n)
    						ans[i][j + 1] = a[i][j];
    					else
    						ans[i][1] = a[i][j];
    				}
    			}
    
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++)
    					cout << a[i][j] << " ";
    				cout << endl;
    			}
    		} else if( x == 5) {
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					ans[i][j] = a[n - j + 1][i];
    				}
    			}
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++)
    					cout << a[i][j] << " ";
    				cout << endl;
    			}
    		} else if( x == 6) {
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					ans[i][j] = a[n - j + 1][i];
    				}
    			}
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					ans[i][j] = a[n - j + 1][i];
    				}
    			}
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++)
    					cout << a[i][j] << " ";
    				cout << endl;
    			}
    		} else {
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					ans[i][j] = a[n - j + 1][i];
    				}
    			}
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					ans[i][j] = a[n - j + 1][i];
    				}
    			}
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++) {
    					ans[i][j] = a[n - j + 1][i];
    				}
    			}
    			memcpy(a , ans , sizeof(a));
    			for(int i = 1; i <= n; i++) {
    				for(int j = 1; j <= n; j++)
    					cout << a[i][j] << " ";
    				cout << endl;
    			}
    		}
    		cout << endl;
    	}
    
    	return 0;
    }
    

信息

ID
2956
时间
1000ms
内存
256MiB
难度
7
标签
递交数
650
已通过
167
上传者