当前位置:网站首页>蛇形矩阵
蛇形矩阵
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;
}边栏推荐
- Longyuan war "epidemic" 2021 network security competition web easyjaba
- 【虚幻引擎UE】实现背景模糊下近景旋转操作物体的方法及踩坑记录
- UI automation test farewell to manual download of browser driver
- How to solve the problem that easycvr changes the recording storage path and does not generate recording files?
- Fuel consumption calculator
- 优先使用对象组合,而不是类继承
- C语言课设:影院售票管理系统
- Rome chain analysis
- Phpmailer reported an error: SMTP error: failed to connect to server: (0)
- This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
猜你喜欢

【FineBI】使用FineBI制作自定义地图过程

【刷题】BFS题目精选

As soon as I write the code, President Wang talks with me about the pattern all day

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?

MacBook安装postgreSQL+postgis

IronXL for . NET 2022.6

灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?

行为感知系统

Wechat applet development process (with mind map)

在线SQL转Excel(xls/xlsx)工具
随机推荐
小程序中实现文章的关注功能
Pyqt5 displays file names and pictures
Kwai, Tiktok, video number, battle content payment
北京程序员的真实一天!!!!!
【刷题】BFS题目精选
Phpmailer reported an error: SMTP error: failed to connect to server: (0)
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
Fuel consumption calculator
How is the entered query SQL statement executed?
How to realize real-time audio and video chat function
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
MindFusion. Virtual Keyboard for WPF
The new project Galaxy token just announced by coinlist is gal
Is there a sudden failure on the line? How to make emergency diagnosis, troubleshooting and recovery
Uni app change the default component style
FFmepg使用指南
Why is there a reincarnation of 60 years instead of 120 years in the tiangan dizhi chronology
3. Package the bottom navigation tabbar
Interview related high-frequency algorithm test site 3
【UNIAPP】系统热更新实现思路