求助站外题!!!
  • 板块学术版
  • 楼主lnscq
  • 当前回复5
  • 已保存回复5
  • 发布时间2023/6/24 22:54
  • 上次更新2023/11/3 12:28:29
查看原帖
求助站外题!!!
553498
lnscq楼主2023/6/24 22:54

原题

#include<bits/stdc++.h>
using namespace std;

int n;
int nowx,nowy;
int value;
int a[50][50];
int main(){
	memset(a,0,sizeof(a));
	scanf("%d",&n);
	n=2*n-1;
	a[1][n/2]=1;
	while(value<n*n){
		value++;
		if(nowx==1&&nowy==n){
			nowx++;
			a[nowx][nowy]=value;
		}else if(nowx==1){
			nowx=n;
			nowy++;
			a[nowx][nowy]=value;
		}else if(nowy==n){
			nowy=1;
			nowx--;
			a[nowx][nowy]=value;
		}else{
			if(a[nowx+1][nowy-1]!=0){
				nowx++;
				a[nowx][nowy]=value;
			}else{
				nowx--;
				nowy++;
				a[nowx][nowy]=value;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			printf("%d ",a[i][j]);
		}
		printf("\n");
	}
	return 0;
}

没有输出是为什么

2023/6/24 22:54
加载中...