当前位置:网站首页>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.
边栏推荐
猜你喜欢

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

FTP的两种模式详解

【Leetcode刷题】数组1——双指针

Ue5 light shadow basic shadow full resolution sawtooth shadow solution lumen

Leetcode 344. reverse string

Official tutorial redshift 07 instances and proxy

Abstract encapsulation inheritance polymorphism

基于udp通信的在线多人聊天室

八、 网络安全

虹科为您分享EtherCAT demo,教您如何从其他协议快速过渡到EtherCAT工业总线
随机推荐
EtherCAT主站掉线后,如何保证目标系统免受故障影响?
Shell tool finalshell
Redshift还原SP效果 - SP贴图导出设置及贴图导入配置
官方教程 Redshift 05 system参数详细解释
Unity-默认渲染管线-刻晴卡渲shader
Vivado IP核之定点数转为浮点数Floating-point
模型空间下的旋转和世界空间下的旋转
LeetCode #9.回文数
官方教程 Redshift 02 4中GI引擎概述及总结
官方教程 Redshift 01 基础理论知识和基础特性学习
Personal views on time complexity
虹科白皮书 | 在工业4.0阶段,如何利用TSN时间敏感网络技术打造数字化工厂?
虹科分享 | 带你全面了解“CAN总线错误”(四)——在实践中生产和记录CAN错误
Dynamic planning summary
UE5 landscape 换算 Nanite 转换方式及不支持 配合 Lumen及Lumen开启 Dynamic Mesh 使用方法
[beauty of software engineering - column notes] 13 | how to break the rhythm of writing code during daytime meetings and overtime?
LeetCode #13. 罗马数字转整数
Ue5 light shadow basic shadow full resolution sawtooth shadow solution lumen
使用STP生成树协议解决网络中的二层环路问题
Official tutorial redshift 05 system parameter detailed explanation