0分求助
查看原帖
0分求助
270889
⚡️行云流水楼主2020/5/13 17:03
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main(){
    int n,a[101][101],x,y,tot;
    tot=x=y=1;
    scanf("%d",&n);
    while(tot<=n*n)
    {
        while(y<=n&&x>=1){
            a[x][y]=tot++;
            x--;
            y++;
        }
        x++;
        if(y>n){
            x++;
            y--;
        }
        while(x<=n&&y>=1){
            a[x][y]=tot++;
            x++;
            y--;
        }
        y++;
        if(x>n){
            x--;
            y++;
        }
    }
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=n;j++)
           printf("%d ",a[i][j]);
           printf("\n");
       
   }
    return 0;
}

0分求助

2020/5/13 17:03
加载中...