当前位置:网站首页>Serpentine matrix
Serpentine matrix
2022-07-05 04:11:00 【Learning 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){
// Judge whether it is horizontal or vertical
if(j < n-1)
j++;
else
i++;
s[i][j] = ans++;
// The lower left
while(j>0 && i < n-1){
j--;i++;
s[i][j] = ans++;
}
// Judge whether it is horizontal or vertical
if(i < n-1)
i++;
else
j++;
s[i][j] = ans++;
// The upper right
while(i>0 && j<n-1){
j++;i--;
s[i][j] = ans++;
}
}
init();
return 0;
}
边栏推荐
- Threejs implements labels and displays labels with custom styles
- 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?
- A應用喚醒B應該快速方法
- [array]566 Reshape the matrix - simple
- @The problem of cross database query invalidation caused by transactional annotation
- 学习MVVM笔记(一)
- 陇原战“疫“2021网络安全大赛 Web EasyJaba
- [Chongqing Guangdong education] 2408t Chinese contemporary literature reference test in autumn 2018 of the National Open University
- 快手、抖音、视频号交战内容付费
- Special Edition: spreadjs v15.1 vs spreadjs v15.0
猜你喜欢
10种寻址方式之间的区别
UI automation test farewell to manual download of browser driver
Differences among 10 addressing modes
行为感知系统
北京程序员的真实一天!!!!!
NetSetMan pro (IP fast switching tool) official Chinese version v5.1.0 | computer IP switching software download
Online sql to excel (xls/xlsx) tool
Common features of ES6
UI自動化測試從此告別手動下載瀏覽器驅動
Use Firefox browser to quickly pick up Web image materials
随机推荐
About the recent experience of writing questions
As soon as I write the code, President Wang talks with me about the pattern all day
[wp][introduction] brush weak type questions
Mixed compilation of C and CC
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
Use threejs to create geometry, dynamically add geometry, delete geometry, and add coordinate axes
Convert Boolean to integer value PHP - Convert Boolean to integer value PHP
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?
A应用唤醒B应该快速方法
mysql的七种join连接查询
行为感知系统
Realize the attention function of the article in the applet
MacBook安装postgreSQL+postgis
在线文本行固定长度填充工具
学习MVVM笔记(一)
Threejs factory model 3DMAX model obj+mtl format, source file download
Open graph protocol
Behavior perception system
Online sql to excel (xls/xlsx) tool
Use of vscode software