RT,他卡住了
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
int ma[350][350];
int x=1, y=0;
int k = 1;
int r = n, l=1;
int t = 1, d=n;
for(int i = 1; i<=n*n; ++i)
{
if(k == 1)
{
y++;
if(y < r)
{
ma[x][y] = i;
}
else
{
ma[x][y] = i;
k = 2;
t++;
}
}
else if(k == 2)
{
x++;
if(x<d)
{
ma[x][y] = i;
}
else
{
ma[x][y] = i;
k = 3;
r--;
}
}
else if(k == 3)
{
y--;
if(y>l)
{
ma[x][y] = i;
}
else
{
ma[x][y] = i;
k = 4;
d -- ;
}
}
else if(k == 4)
{
y--;
if(y>t)
{
ma[x][y] = i;
}
else
{
ma[x][y] = i;
l++;
k = 1;
}
}
}
for(int i=1; i<=n ;++i)
{
for(int j=1; j<=n; ++j)
{
printf("%3d",ma[i][j]);
}
printf("\n");
}
}```