输出没问题,为啥只有20分
查看原帖
输出没问题,为啥只有20分
1412216
dhc130223楼主2024/11/24 16:24
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100][100]={0},ans=1,x=1,y=1;
	cin>>n;
	while(ans<=n*n){
		while(y<=n&&a[x][y]==0){
		a[x][y]=ans;y++;ans++;}
		y--;x++;
		while(x<=n&&a[x][y]==0){
		a[x][y]=ans;x++;ans++;}
		x--;y--;
		while(y>=1&&a[x][y]==0){
		a[x][y]=ans;y--;ans++;}
		y++;x--;
		while(x>=1&&a[x][y]==0){
		a[x][y]=ans;x--;ans++;}
		x++;y++;
	}
	for(x=1;x<=n;x++){
		for(y=1;y<=n;y++){
			cout<<setw(3)<<a[x][y]<<' ';
		}
		cout<<endl;
	}
}
2024/11/24 16:24
加载中...