当前位置:网站首页>7110 digital trend 2 solution
7110 digital trend 2 solution
2022-07-29 06:28:00 【C2024XSC249】
Link Click to see the original question
Digital trend 2
2021.8.15 Regular practice of two-dimensional array 3 B topic
This problem is a very simple two-dimensional array problem , It is also a simulation problem :
First step : Definition and input
Define length and array a a a.
int a[MAXN][MAXN], n;
Enter n n n Value .
This is too l o u lou lou 了 , If you don't want to learn again
The second step : simulation
Define the variables needed for the simulation
We define a counting variable s t e p step step, Count the steps taken .( That is, several numbers )
Then define its coordinates x 、 y x、y x、y.
int step, x = 0, y = 1;// Because the first step is to go down , therefore x Self acting 0
simulation
| \ | The first 1 Column | The first 2 Column | The first 3 Column | The first 4 Column | The first 5 Column |
|---|---|---|---|---|---|
| The first 1 That's ok | a 1 , 1 a_{1,1} a1,1 | a 1 , 2 a_{1,2} a1,2 | a 1 , 3 a_{1,3} a1,3 | a 1 , 4 a_{1,4} a1,4 | a 1 , 5 a_{1,5} a1,5 |
| The first 2 That's ok | a 2 , 1 a_{2,1} a2,1 | a 2 , 2 a_{2,2} a2,2 | a 2 , 3 a_{2,3} a2,3 | a 2 , 4 a_{2,4} a2,4 | a 2 , 5 a_{2,5} a2,5 |
| The first 3 That's ok | a 3 , 1 a_{3,1} a3,1 | a 3 , 2 a_{3,2} a3,2 | a 3 , 3 a_{3,3} a3,3 | a 3 , 4 a_{3,4} a3,4 | a 3 , 5 a_{3,5} a3,5 |
| The first 4 That's ok | a 4 , 1 a_{4,1} a4,1 | a 4 , 2 a_{4,2} a4,2 | a 4 , 3 a_{4,3} a4,3 | a 4 , 4 a_{4,4} a4,4 | a 4 , 5 a_{4,5} a4,5 |
| The first 5 That's ok | a 5 , 1 a_{5,1} a5,1 | a 5 , 2 a_{5,2} a5,2 | a 5 , 3 a_{5,3} a5,3 | a 5 , 4 a_{5,4} a5,4 | a 5 , 5 a_{5,5} a5,5 |
Go down
The condition to judge when going down is :
1. Not out of array ;
2. There are no numbers in the lower grid .
The code is as follows :
while (x + 1 <= n && a[x + 1][y] == 0) {
a[++ x][y] = ++ step;
}
turn right
The condition to judge when walking to the right is :
1. Not out of array ;
2. There are no numbers in the grid on the right .
The code is as follows :
while (y + 1 <= n && a[x][y + 1] == 0) {
a[x][++ y] = ++ step;
}
Go up
The condition to judge is :
1. Not out of array ;
2. There are no numbers in the upper grid .
The code is as follows :
while (x - 1 >= 1 && a[x - 1][y] == 0) {
a[-- x][y] = ++ step;
}
turn left
The condition to judge when walking left is :
1. Not out of array ;
2. There are no numbers in the grid on the left .
The code is as follows :
while (y - 1 >= 1 && a[x][y - 1] == 0) {
a[x][-- y] = ++ step;
}
The third step : Output
With two f o r for for Loop nested output .
Be careful : It should be output like this
Place holder :%4d
printf ("%4d", a[i][j]);
And finally
Want full code ? No way
And finally : Plagiarism is useless
Thank you for watching.
边栏推荐
- [leetcode skimming] array 1 - double pointer
- Unity初学3——敌人的移动控制和掉血区域的设置(2d)
- FPGA里两个数的大小直接进行比较就可以吗?
- 钓鱼邮件处置
- Official tutorial redshift 09 camera
- V-ray 5 ACEScg 工作流程设置
- Leetcode 19. delete the penultimate node of the linked list
- 摊余成本最牛例子
- [beauty of software engineering - column notes] 16 | how to write project documents?
- 【Leetcode刷题】数组1——双指针
猜你喜欢

Official tutorial redshift 05 system parameter detailed explanation

Official tutorial redshift 09 camera

角色shader小练习

Vivado IP核之浮点数开方 Floating-point

Leetcode 167. sum of two numbers II - input ordered array

Ue5 texture system explanation and common problem setting and Solutions

MySQL interview questions

V-ray 5 ACEScg 工作流程设置

计算机网络面试题

Leetcode 14. longest public prefix
随机推荐
Operating system interview questions
虹科Automation softPLC | MoDK运行环境与搭建步骤(1)——运行环境简介
角色shader小练习
Computer network interview questions
官方教程 Redshift 05 AOVs
虹科分享 | 带您全面认识“CAN总线错误”(一)——CAN总线错误与错误帧
Unity中简单的matcap+fresnel shader的实现
Understanding of synchronized eight lock phenomenon
电脑鼠标右键单击总是转圈圈怎么回事
Simple code to realize PDF to word document
leetcode刷题笔记 763.划分字母区间(中等)
LeetCode #1.两数之和
Leetcode 283. move zero
赛博朋克版特效shader
进程与线程
Self study understanding of [chain forward star]
Official tutorial redshift 05 AOVs
Access、Hybrid和Trunk三种模式的理解
Maya aces workflow configuration (Arnold and redshift map configuration specification - restore the correct effect of the map under the SP aces process) PS restore the rendered map under the aces proc
Number theory: proof that the maximum number that px+py cannot represent is pq-p-q