1 solutions

  • 1
    @ 2022-5-1 1:08:32
    #include<iostream>
    using namespace std;
    const int N=1e3+7;
    int n;
    int ma[N][N];
    int main(){
    	cin>>n;
    	int cnt=n;
    	int len=2*n+1;
    	for(int i=1,j=1;i<=n;i++,j++){
    		for(int k=j;k<=len-i+1;k++)ma[i][k]=cnt;
    		for(int k=i;k<=len-j+1;k++)ma[k][j]=cnt;
    		cnt--;
    	}
    	cnt=n;
    	for(int i=len,j=len;i>=n;i--,j--){
    		for(int k=j;k>=len-i+1;k--)ma[i][k]=cnt;
    		for(int k=i;k>=len-j+1;k--)ma[k][j]=cnt;
    		cnt--;
    	}
    	for(int i=1;i<=len;i++){
    		for(int j=1;j<=len;j++)
    			printf("%2d",ma[i][j]);
    		printf("\n");
    	}
    	return 0;
    }
    
    
    • 1

    Information

    ID
    549
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    10
    Tags
    # Submissions
    1
    Accepted
    1
    Uploaded By