当前位置:网站首页>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;
}
}
}边栏推荐
- arthas watch 抓取入参的某个字段/属性
- Arthas watch grabs a field / attribute of the input parameter
- MongoDB 慢查询语句优化分析策略
- 有道云笔记
- Classes in TS
- [set theory] set concept and relationship (set represents | number set | set relationship | contains | equality | set relationship property)
- Sklearn data preprocessing
- Mongodb slow query optimization analysis strategy
- Priv-app permission异常
- Drf--- quick start 01
猜你喜欢

MC Layer Target

After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed

Employee attendance management system based on SSM

有道云笔记
![[Thesis Writing] how to write the overall design of JSP tourism network](/img/02/841e8870c2ef871c182b9bb8252a83.jpg)
[Thesis Writing] how to write the overall design of JSP tourism network

FISCO bcos zero knowledge proof Fiat Shamir instance source code

Which code editor is easy to use? Code editing software recommendation

JS realizes lazy loading of pictures

跨境电商多商户系统怎么选

540. Single element in ordered array
随机推荐
Some information about the developer environment in Chengdu
GFS分布式文件系统(光是遇见已经很美好了)
一名外包仔的2022年中总结
When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error
Redraw and reflow
vulnhub HA: Natraj
Reptile exercise 03
[set theory] Cartesian product (concept of Cartesian product | examples of Cartesian product | properties of Cartesian product | non commutativity | non associativity | distribution law | ordered pair
SSM based campus part-time platform for College Students
[set theory] binary relationship (special relationship type | empty relationship | identity relationship | global relationship | divisive relationship | size relationship)
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
AWS VPC
解决bp中文乱码
Use the benchmarksql tool to perform a data prompt on kingbases. The jdbc driver cannot be found
Dive into deep learning - 2.1 data operation & Exercise
How to use kotlin to improve productivity: kotlin tips
The latest activation free version of Omni toolbox
JS realizes the animation effect of text and pictures in the visual area
mysql字段userid逗号分开保存按userid查询
FFMpeg filter