当前位置:网站首页>蛇形矩阵
蛇形矩阵
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;
}
边栏推荐
- WGS84 coordinate system, web Mercator, gcj02 coordinate system, bd09 coordinate system - brief introduction to common coordinate systems
- MindFusion.Virtual Keyboard for WPF
- Clickhouse synchronization MySQL (based on materialization engine)
- PlasticSCM 企业版Crack
- 在线SQL转Excel(xls/xlsx)工具
- Use Firefox browser to quickly pick up Web image materials
- A應用喚醒B應該快速方法
- Threejs realizes the drawing of the earth, geographical location annotation, longitude and latitude conversion of world coordinates threejs coordinates
- Use object composition in preference to class inheritance
- Threejs factory model 3DMAX model obj+mtl format, source file download
猜你喜欢
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?
在线文本行固定长度填充工具
Online sql to excel (xls/xlsx) tool
Rust区块琏开发——签名加密与私钥公钥
Containerd series - what is containerd?
How to use jedis of redis
What is test development? Why do so many companies hire test developers now?
Threejs Internet of things, 3D visualization of farm (III) model display, track controller setting, model moving along the route, model adding frame, custom style display label, click the model to obt
MindFusion.Virtual Keyboard for WPF
【UNIAPP】系统热更新实现思路
随机推荐
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
The order of LDS links
【虚幻引擎UE】打包报错出现!FindPin错误的解决办法
如何实现实时音视频聊天功能
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
MindFusion.Virtual Keyboard for WPF
我国算力规模排名全球第二:计算正向智算跨越
Possible stack order of stack order with length n
Threejs Internet of things, 3D visualization of factory
Scheduling system of kubernetes cluster
How to use jedis of redis
IronXL for . NET 2022.6
3. Package the bottom navigation tabbar
技术教程:如何利用EasyDSS将直播流推到七牛云?
[array]566 Reshape the matrix - simple
Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
Interview byte, pass the exam and directly work on three sides. As a result, I found an architect to hang me?
北京程序员的真实一天!!!!!
EasyCVR更改录像存储路径,不生成录像文件如何解决?
官宣!第三届云原生编程挑战赛正式启动!