好久没写算法题了,先写个语法题练练手
https://www.acwing.com/problem/content/description/758/
#include<iostream>
using namespace std;
const int N = 105;
int map[N][N];
int n,m;
int i=1,j=0;
int main()
{
cin >> n >> m;
int num=1;
while(num<=n*m)
{
while(map[i][j+1]==0 && j<m)map[i][j+1]=num++,j++;//right
while(map[i+1][j]==0 && i<n)map[i+1][j]=num++,i++;//down
while(map[i][j-1]==0 && j>1)map[i][j-1]=num++,j--;//left
while(map[i-1][j]==0 && i>1)map[i-1][j]=num++,i--;//up
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
cout << map[i][j] << " ";
puts("");
}
return 0;
}
标签:map,756,int,矩阵,++,num,蛇形,-- From: https://www.cnblogs.com/lxl-233/p/17115137.html