当前位置:网站首页>Hj35 serpentine matrix
Hj35 serpentine matrix
2022-07-03 04:29:00 【ChasnyChang】
describe
The snake matrix is made up of 1 The starting natural numbers are arranged in turn into a triangle on the matrix .
for example , When the input 5 when , The triangle that should be output is :
1 3 6 10 15
2 5 9 14
4 8 13
7 12
11
Please note that this question contains multiple sets of sample inputs .
Input description :
Enter a positive integer N(N No more than 100)
Output description :
Output one N Snake matrix of row .
Example 1
Input :
4
Copy output :
1 3 6 10 2 5 9 4 8 7
Challenge the most garbage practice in the whole network
#include<iostream>
using namespace std;
int main()
{
int n;
while (cin >> n)
{
int i = 1, j = n, shownum = 0, cnt = 0;
bool flag = true;
int coladdval = 0;
for (; i <= n; i++) //n=4 when , 4 That's ok
{
cnt = i+1; // The first number at the beginning of each line increases gradually
for (; j >= 1; j--) // Column decrement per row
{
if (flag) // The first output of each line
{
shownum = i + coladdval;
cout << shownum << " ";
flag = false;
}
else // Output of other columns per row
{
shownum += cnt;
cout << shownum << " ";
cnt++;
}
}
j = n - i; // Control the output of each column
flag = true;
coladdval += i - 1;
cout << "\n";
}
// n = 0;
}
return 0;
}Give me another beautiful
#include<iostream>
using namespace std;
int main()
{
int a;
while (cin >> a)
{
int m = 1;
int n;
for (int i = 0; i < a; i++)
{
m += i;
for (int j = i; j < a; j++)
{
int c = 1 + j;
if (j == i)
{
n = m;
cout << n << " ";
}
else {
cout << (n += c) << " ";
}
}
cout << endl;
}
}
}边栏推荐
- [set theory] set concept and relationship (set family | set family examples | multiple sets)
- After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me
- 有道云笔记
- [set theory] binary relationship (definition field | value field | inverse operation | inverse synthesis operation | restriction | image | single root | single value | nature of synthesis operation)
- Kingbasees plug-in KDB of Jincang database_ date_ function
- 智能合约安全审计公司选型分析和审计报告资源下载---国内篇
- How to process the current cell with a custom formula in conditional format- How to address the current cell in conditional format custom formula?
- [free completion] development of course guidance platform (source code +lunwen)
- Ffmpeg tanscoding transcoding
- [Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
猜你喜欢
![[NLP]—sparse neural network最新工作简述](/img/65/35ae0137f4030bdb2b0ab9acd85e16.png)
[NLP]—sparse neural network最新工作简述

Two drawing interfaces - 1 Matlab style interface

Auman Galaxy new year of the tiger appreciation meeting was held in Beijing - won the double certification of "intelligent safety" and "efficient performance" of China Automotive Research Institute
![[graduation season · aggressive technology Er] Confessions of workers](/img/ec/4f4d96e22a1029074b07ab80bfa1d9.png)
[graduation season · aggressive technology Er] Confessions of workers

2022 registration of G2 utility boiler stoker examination and G2 utility boiler stoker reexamination examination

Arthas watch grabs a field / attribute of the input parameter

Design and implementation of JSP logistics center storage information management system

The latest activation free version of Omni toolbox

After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me

X-ray normal based contour rendering
随机推荐
使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错
[set theory] binary relationship (special relationship type | empty relationship | identity relationship | global relationship | divisive relationship | size relationship)
What's wrong with SD card data damage? How to recover SD card data damage
有道云笔记
Basic MySQL operations
Competitive product analysis and writing
2022-02-14 (394. String decoding)
Kubernetes source code analysis (I)
2022-02-13 (347. Top k high frequency elements)
mysql字段userid逗号分开保存按userid查询
How to choose cross-border e-commerce multi merchant system
IPhone x forgot the boot password
Fcpx template: sweet memory electronic photo album photo display animation beautiful memory
[Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
SSM based campus part-time platform for College Students
[fxcg] market analysis today
Integration of Android high-frequency interview questions (including reference answers)
Matplotlib -- save graph
Writing skills of multi plate rotation strategy -- strategy writing learning materials
FFMpeg example