当前位置:网站首页>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.
边栏推荐
- Official tutorial redshift 03 parameters and general instructions of various GI
- SQL Developer图形化窗口创建数据库(表空间和用户)
- MySQL interview questions
- Leetcode 189. rotation array
- FPGA里两个数的大小直接进行比较就可以吗?
- JVM内存结构
- 角色shader小练习
- Leetcode 344. reverse string
- 官方教程 Redshift 09 Camera
- Leetcode 167. sum of two numbers II - input ordered array
猜你喜欢

SQL Developer图形化窗口创建数据库(表空间和用户)

虹科分享 | 如何测试与验证复杂的FPGA设计(1)——面向实体或块的仿真

只让电脑运行某个程序设置

基于TCP的在线词典

Leetcode 1. sum of two numbers
![[beauty of software engineering - column notes] 19 | as a programmer, you should have product awareness](/img/32/180bfe5904366946fca0d987f4e8ad.png)
[beauty of software engineering - column notes] 19 | as a programmer, you should have product awareness

leetcode---技巧

UE5 纹理系统讲解及常见问题设置及解决方案

Eight sorts --------- quick sort

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
随机推荐
THINKPHP5 常见问题
JVM内存结构
Navicat for Oracle Cannot create oci environment
Leetcode 3. longest substring without repeated characters
Leetcode 189. rotation array
Redshift restore SP effect - SP map export settings and map import configuration
Linked list -------------------------- tail insertion method
动态规划总结
PDO的使用
Leetcode scribble notes 763. Divide the letter range (medium)
Eight sorts ----------- bubble sort
文件系统一
基于TCP的在线词典
Traditional model predictive control trajectory tracking - circular trajectory (function package has been updated)
使用STP生成树协议解决网络中的二层环路问题
Computer network interview questions
Leetcode 35. search insertion location
官方教程 Redshift 05 AOVs
Leetcode 1. sum of two numbers
Unity-默认渲染管线-刻晴卡渲shader