当前位置:网站首页>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 #283.移动零
LeetCode #26.删除有序数组中的重复项
THINKPHP5 常见问题
Official tutorial redshift 07 instances and proxy
Leetcode 283. move zero
TCP套接口通信实验
Eight sorts ------------- heap sort
操作系统面试题
Access、Hybrid和Trunk三种模式的理解
Sliding window leetcode 76. minimum covering substring (hard) 76.76. minimumwindow substring (hard)
Ue5 light shadow basic shadow full resolution sawtooth shadow solution lumen
使用STP生成树协议解决网络中的二层环路问题
Official tutorial redshift 05 AOVs
九、 组网技术
虹科Automation softPLC | 虹科KPA MoDK运行环境与搭建步骤(2)——MoDK运行环境搭建
文件系统一
Unity初学4——帧动画以及主角攻击(2d)
[beauty of software engineering - column notes] 17 | what is the need analysis? How to analyze?
[leetcode skimming] array 1 - double pointer
Redshift restore SP effect - SP map export settings and map import configuration









