当前位置:网站首页>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;
}
}
}
边栏推荐
- Asp access teaching management system design finished product
- Drf--- quick start 01
- After job hopping at the end of the year, I interviewed more than 30 companies in two weeks and finally landed
- [fairseq] 报错:TypeError: _broadcast_coalesced(): incompatible function arguments
- Dismantle a 100000 yuan BYD "Yuan". Come and see what components are in it.
- Integration of Android high-frequency interview questions (including reference answers)
- Which Bluetooth headset is good about 400? Four Bluetooth headsets with strong noise reduction are recommended
- 使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
- Ffmpeg mix
- Pdf editing tool movavi pdfchef 2022 direct download
猜你喜欢
SSM based campus part-time platform for College Students
FFMpeg filter
4 years of experience to interview test development, 10 minutes to end, ask too
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
2022 a special equipment related management (elevator) analysis and a special equipment related management (elevator) simulation test
How to choose cross-border e-commerce multi merchant system
Solve BP Chinese garbled code
[fxcg] inflation differences will still lead to the differentiation of monetary policies in various countries
A outsourcing boy's mid-2022 summary
JVM原理简介
随机推荐
[literature reading] sparse in deep learning: practicing and growth for effective information and training in NN
Human resource management system based on JSP
[set theory] set operation (Union | intersection | disjoint | relative complement | symmetric difference | absolute complement | generalized union | generalized intersection | set operation priority)
Interface in TS
2022 a special equipment related management (elevator) analysis and a special equipment related management (elevator) simulation test
使用BENCHMARKSQL工具对kingbasees并发测试时kill掉主进程成功后存在子线程未及时关闭
Introduction of pointer variables in function parameters
解决bp中文乱码
C language series - Section 3 - functions
Arthas watch grabs a field / attribute of the input parameter
智能合约安全审计公司选型分析和审计报告资源下载---国内篇
Two points -leetcode-540 A single element in an ordered array
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
FuncS sh file not found when using the benchmarksql tool to test kingbases
Competitive product analysis and writing
使用BENCHMARKSQL工具对kingbaseES执行灌数据提示无法找到JDBC driver
AWS VPC
Two drawing interfaces - 1 Matlab style interface
[free completion] development of course guidance platform (source code +lunwen)
因子选股-打分模型