当前位置:网站首页>蛇形矩阵
蛇形矩阵
2022-07-05 04:08:00 【学习kl&tk】

#include"bits/stdc++.h"
using namespace std;
int s[105][105];
int n;
void init(){
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
printf("%d ",s[i][j]);
cout << endl;
}
}
int main()
{
cin >> n;
int ans = 1;
int i = 0 , j = 0;
s[0][0]=ans++;
while(ans < n*n){
// 判断横着还是竖着
if(j < n-1)
j++;
else
i++;
s[i][j] = ans++;
//左下
while(j>0 && i < n-1){
j--;i++;
s[i][j] = ans++;
}
// 判断横着还是竖着
if(i < n-1)
i++;
else
j++;
s[i][j] = ans++;
//右上
while(i>0 && j<n-1){
j++;i--;
s[i][j] = ans++;
}
}
init();
return 0;
}边栏推荐
- Threejs realizes rain, snow, overcast, sunny, flame
- error Couldn‘t find a package. JSON file in "your path“
- Study notes 7
- Why can't all browsers on my computer open web pages
- 【看完就懂系列】一文6000字教你从0到1实现接口自动化
- kubernetes集群之调度系统
- 我就一写代码的,王总整天和我谈格局...
- UI自動化測試從此告別手動下載瀏覽器驅動
- 快手、抖音、视频号交战内容付费
- Ctfshow 2022 Spring Festival welcome (detailed commentary)
猜你喜欢

【虚幻引擎UE】运行和启动的区别,常见问题分析

Containerd series - what is containerd?

“金九银十”是找工作的最佳时期吗?那倒未必

Special Edition: spreadjs v15.1 vs spreadjs v15.0

Plasticscm enterprise crack

Behavior perception system

C language course setting: cinema ticket selling management system

Use Firefox browser to quickly pick up Web image materials

Threejs rendering obj+mtl model source code, 3D factory model

Why do big companies such as Baidu and Alibaba prefer to spend 25K to recruit fresh students rather than raise wages by 5K to retain old employees?
随机推荐
Scheduling system of kubernetes cluster
This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
Threejs realizes sky box, panoramic scene, ground grass
Rust区块琏开发——签名加密与私钥公钥
EasyCVR更改录像存储路径,不生成录像文件如何解决?
企业级:Spire.Office for .NET:Platinum|7.7.x
Special Edition: spreadjs v15.1 vs spreadjs v15.0
Kwai, Tiktok, video number, battle content payment
provide/inject
Sequelize. JS and hasmany - belongsto vs hasmany in serialize js
在线文本行固定长度填充工具
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
Interview byte, pass the exam and directly work on three sides. As a result, I found an architect to hang me?
JVM garbage collection
长度为n的入栈顺序的可能出栈顺序种数
Alibaba cloud ECS uses cloudfs4oss to mount OSS
Laravel8 export excel file
【FineBI】使用FineBI制作自定义地图过程
Ctfshow 2022 Spring Festival welcome (detailed commentary)