当前位置:网站首页>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;
}
}
}边栏推荐
- [Chongqing Guangdong education] reference materials for design and a better life of Zhongyuan Institute of science and technology
- 使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
- JVM原理简介
- 220214c language learning diary
- GFS distributed file system (it's nice to meet it alone)
- Xrandr modifier la résolution et le taux de rafraîchissement
- 540. Single element in ordered array
- Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
- [fxcg] market analysis today
- 使用BENCHMARKSQL工具对KingbaseES预热数据时执行:select sys_prewarm(‘NDX_OORDER_2 ‘)报错
猜你喜欢

arthas watch 抓取入参的某个字段/属性

Internationalization and localization, dark mode and dark mode in compose

When using the benchmarksql tool to preheat data for kingbasees, execute: select sys_ Prewarm ('ndx_oorder_2 ') error

Asp access teaching management system design finished product

Competitive product analysis and writing

SSM based campus part-time platform for College Students

MC Layer Target

2022 P cylinder filling test content and P cylinder filling simulation test questions

Web - Information Collection

A outsourcing boy's mid-2022 summary
随机推荐
怎么用Kotlin去提高生产力:Kotlin Tips
4 years of experience to interview test development, 10 minutes to end, ask too
Xrandr modify resolution and refresh rate
Design and implementation of JSP logistics center storage information management system
MongoDB 慢查询语句优化分析策略
FISCO bcos zero knowledge proof Fiat Shamir instance source code
Reptile exercise 03
[no title] 2022 chlorination process examination content and free chlorination process examination questions
重绘和回流
vulnhub HA: Natraj
Two drawing interfaces - 1 Matlab style interface
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
Database management tool, querious direct download
When using the benchmarksql tool to test the concurrency of kingbasees, there are sub threads that are not closed in time after the main process is killed successfully
After reviewing MySQL for a month, I was stunned when the interviewer of Alibaba asked me
[set theory] set concept and relationship (true subset | empty set | complete set | power set | number of set elements | power set steps)
Joint set search: merge intervals and ask whether two numbers are in the same set
I've been in software testing for 8 years and worked as a test leader for 3 years. I can also be a programmer if I'm not a professional
[graduation season · aggressive technology Er] Confessions of workers
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭