蛇形填数(矩阵)

#include <bits/stdc++.h>

using namespace std;

int main() {

int a1010 = {0};

int n;

cin >> n;

int num = 1;

int bot = n - 1;

int top = 0;

int left = 0;

int right = n - 1;

while (n * n >= num) {

for (int i = top; i <= bot; i++) {

airight = num++;

}

right--;

if (top <= bot) {

for (int j = right; j >= left; j--) {

abotj = num++;

}

bot--;

}

if (right >= left) {

for (int i = bot; i >= top; i--) {

aileft = num++;

}

left++;

}

for (int j = left; j <= right; j++) {

atopj = num++;

}

top++;

}

for (int i = 0; i < n; i++) {

for (int j = 0; j < n; j++) {

cout << setw(4) << aij;

}

cout << endl;

}

return 0;

}

相关推荐
L_09076 小时前
【C++】异常
开发语言·c++
liulilittle6 小时前
关于拥塞控制的几点思考
网络·c++·tcp/ip·计算机网络·信息与通信·tcp·通信
QT-Neal8 小时前
C++ 编码规范
c++
啦啦啦啦啦zzzz9 小时前
数据结构:红黑树理论
数据结构·c++·红黑树
Yolo_TvT9 小时前
C++:默认构造函数
c++
小欣加油11 小时前
leetcode994 腐烂的橘子
数据结构·c++·算法·leetcode·bfs
.千余11 小时前
【C++】手写双向链表:list容器模拟实现
开发语言·c++·笔记·学习·其他
liulilittle12 小时前
过冲:拥塞控制的呼吸与盲行
linux·网络·c++·tcp/ip·计算机网络·tcp·通信
小欣加油12 小时前
leetcode2574 左右元素和的差值
数据结构·c++·算法·leetcode·职场和发展
weixin_4617694012 小时前
通过数组和队列构造二叉树方法(用于算法测试),C++ vector不能直接使用null
数据结构·c++·算法·vector·nullptr·null