文章

1

粉丝

13

获赞

4

访问

189

头像
1216旋转矩阵
我要提问
发布于2025年2月28日 14:19
阅读数 189

为什么我的代码只能通过90%,找了好久都没找到错误
#include<bits/stdc++.h>
using namespace std;
void func1(int a[105][105],int n){
    int cns=0,i=0,j=0;
    if(n==1){
        a[i][j]=1;
        return;
    }
    while(cns!=n*n){
    for(int tem=0;tem<n-1;tem++){
        a[i++][j]=++cns;
    }
    if((cns==n*n))break;
    for(int tem=0;tem<n-1;tem++){
        a[i][j++]=++cns;
    }
    if((cns==n*n))break;
    for(int tem=0;tem<n-1;tem++){
        a[i--][j]=++cns;
    }
    if((cns==n*n))break;
    for(int tem=0;tem<n-1;tem++){
        a[i][j--]=++cns;
    }
 &nb...

登录查看完整内容


登录后发布评论

2 条评论
快乐小土狗
2025年3月2日 03:28

你的代码输入10时,中心都是0

赞(1)

konodio : 回复 快乐小土狗: 谢啦if((cns==n*n))break;那行忘了n已经重新定义过了,现在可以了

2025年3月8日 16:49