当前位置:网站首页>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.
边栏推荐
- [beauty of software engineering - column notes] 16 | how to write project documents?
- Leetcode 26. delete duplicates in the ordered array
- Leetcode 167. sum of two numbers II - input ordered array
- 虹科分享 | 带你全面了解“CAN总线错误”(四)——在实践中生产和记录CAN错误
- Leetcode 977. Square of ordered array
- c语言面试准备一(谈谈理解系类)
- 虹科分享 | 带你全面了解“CAN总线错误”(三)——CAN节点状态与错误计数器
- STP生成树原理及选举规则举例
- Summary of winter vacation training (1.23~1.28) [first tier]
- Access、Hybrid和Trunk三种模式的理解
猜你喜欢
虹科白皮书 | 在工业4.0阶段,如何利用TSN时间敏感网络技术打造数字化工厂?
Official tutorial redshift 07 instances and proxy
Official tutorial redshift 05 system parameter detailed explanation
官方教程 Redshift 05 system参数详细解释
虹科为您分享EtherCAT demo,教您如何从其他协议快速过渡到EtherCAT工业总线
官方教程 Redshift 05 AOVs
Ue5 texture system explanation and common problem setting and Solutions
2022暑初二信息竞赛学习成果分享1
Leetcode 167. sum of two numbers II - input ordered array
虹科Automation softPLC | MoDK运行环境与搭建步骤(1)——运行环境简介
随机推荐
虹科 | 使用JESD204串行接口高速桥接模拟和数字世界
Official tutorial redshift 04 rendering parameters
模型空间下的旋转和世界空间下的旋转
PDO的使用
Traditional model predictive control trajectory tracking - wavy trajectory (function package has been updated)
[leetcode brush questions] array 3 - divide and conquer
LeetCode #9.回文数
七、 下一代互联网IPV6
6898 changing matrix problem solution
Leetcode 14. longest public prefix
Maya ACES工作流程配置(Arnold 及 RedShift 贴图配置规范-还原出SP-Aces流程下贴图正确的效果) PS还原Aces流程下渲染的图
LeetCode #26.删除有序数组中的重复项
虹科分享 | 测试与验证复杂的FPGA设计(2)——如何在IP核中执行面向全局的仿真
电脑系统没有standard tcp/ip port端口的处理操作
虹科分享 | 带你全面认识“CAN总线错误”(二)——CAN错误类型
Leetcode 876. Intermediate node of linked list
【Leetcode刷题】数组2——二分查找
官方教程 Redshift 05 AOVs
Official tutorial redshift 05 system parameter detailed explanation
【Leetcode刷题】数组1——双指针