当前位置:网站首页>蛇形矩阵
蛇形矩阵
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;
}
边栏推荐
- [wp][introduction] brush weak type questions
- Interview byte, pass the exam and directly work on three sides. As a result, I found an architect to hang me?
- 企业级:Spire.Office for .NET:Platinum|7.7.x
- How does the applet solve the rendering layer network layer error?
- 【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
- Mixed compilation of C and CC
- As soon as I write the code, President Wang talks with me about the pattern all day
- A應用喚醒B應該快速方法
- Ctfshow 2022 Spring Festival welcome (detailed commentary)
- BDF application - topology sequence
猜你喜欢
Wechat applet development process (with mind map)
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
Threejs implements labels and displays labels with custom styles
An elegant program for Euclid‘s algorithm
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
[wp]bmzclub writeup of several questions
Pyqt pyside custom telescopic menu bar sharing (including tutorial)
Official announcement! The third cloud native programming challenge is officially launched!
Rome链分析
Kwai, Tiktok, video number, battle content payment
随机推荐
DFS and BFS concepts of trees and graphs
Differences among 10 addressing modes
[charging station]_ Secular wisdom_ Philosophical wisdom _
在线SQL转Excel(xls/xlsx)工具
How does the applet solve the rendering layer network layer error?
已解决(sqlalchemy+pandas.read_sql)AttributeError: ‘Engine‘ object has no attribute ‘execution_options‘
【虚幻引擎UE】运行和启动的区别,常见问题分析
MacBook安装postgreSQL+postgis
Use of vscode software
行为感知系统
Interview related high-frequency algorithm test site 3
Phpmailer reported an error: SMTP error: failed to connect to server: (0)
provide/inject
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
Threejs clicks the scene object to obtain object information, and threejs uses raycaster to pick up object information
快手、抖音、视频号交战内容付费
Containerd series - what is containerd?
Clickhouse materialized view
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
[wp]bmzclub writeup of several questions