蛇形填数(矩阵)

#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;

}

相关推荐
UIU1142 小时前
P1481 魔族密码
c++·算法·动态规划
闻缺陷则喜何志丹8 小时前
【C++特性】四种类型转
c++·算法·类型转换
apcipot_rain11 小时前
C++转Java日记(02)
java·开发语言·c++
杜 硕12 小时前
从零开始的C++生活——第七讲——02
开发语言·c++·生活
Rabitebla20 小时前
【Linux 底层原理】进程(十):进程等待详解---从僵尸进程到 wait、waitpid 与 status
linux·c++·笔记·学习·visual studio
西西弗Sisyphus1 天前
C++ 超时互斥锁(Timed Mutex):std::timed_mutex 与 std::unique_lock
c++
今天要早睡_1 天前
C++01_入门基础复习
开发语言·c++
Fuyo_11191 天前
C++ 运行时多态与虚函数机制全面剖析【面试重点】
开发语言·c++·面试
Chen_harmony1 天前
七、STL与string类
开发语言·c++
xxxiugou1231 天前
C++命名空间与引用全解析
开发语言·c++