文章

12

粉丝

0

获赞

72

访问

856

头像
旋转矩阵--三个操作封装成三个函数,需要时直接调用即可:
P1221 同济大学机试题
发布于2026年3月11日 10:20
阅读数 213

#include<bits/stdc++.h>
using namespace std;
int a[101][101];

void func1(int n,int m){//顺时针旋转90度 
	int temp[n][m];
	for(int i =0;i<n;i++)
    	for(int j=0;j<m;j++)
    		temp[i][j] = a[i][j];//先复制出来
    
    for(int i =0;i<n;i++)
    	for(int j=0;j<m;j++)
    		a[j][n-i-1] = temp[i][j];//对应赋值
    		
}
void func2(int n,int m){//纵向翻折 
	int at =0;
	for(int i =0;i<n;i++)
    	for(int j=0;j<m/2;j++){
    		at = a[i][j];
    		a[i][j] = a[i][m-j-1];
    		a[i][m-j-1] = at;
		}
    		
}
void func3(int n,int m){//逆时针旋转90度 
	int temp[n][m];
	for(int i =0;i<n;i++)
    	for(int j=0;j<m;j++)
    		temp[i][j] = a[i][j];
    
    for(int i =0;i<n;i++)
    	for(int j=0;j<m;j++)
    		a[m-j-1][i] = temp[i][j];
}
int main(){
    int n,m,k;
    while(cin >> n>>m>>k){
    	for(int i =0;i<n;i++)
	    	for(int j=0;j<m;j++)
	    		cin >> a[i][j];
	    		
	    while(k--){
	    	int at ;
	    	c...
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发