当前位置:网站首页>*4-2 CCF 2014-12-2 Z字形扫描
*4-2 CCF 2014-12-2 Z字形扫描
2022-08-09 13:31:00 【叶萧白】
题目描述

样例

源代码
#include<iostream>
#include<cstring>
using namespace std;
const int N = 500;
int flag[N + 1][N + 1];
int n;
int main()
{
cin >> n;
int a=1, b=1;
int i, j;
for (i = 1; i < n + 1; i++)
{
for (j = 1; j < n + 1; j++)
{
cin>>flag[i][j];
}
}
printf("%d ", flag[a][b]);
while (a <= n && b <= n)
{
if (b < n)
{
b++;
if (flag[a][b])
{
printf("%d ", flag[a][b]);
}
}
else if (b == n)
{
a++;
if (flag[a][b])
{
printf("%d ", flag[a][b]);
}
}
while (b > 1&& a<n)
{
b--;
a++;
if (flag[a][b])
{
printf("%d ", flag[a][b]);
}
}
if (a < n)
{
a++;
if (flag[a][b])
{
printf("%d ", flag[a][b]);
}
}
else if (a == n)
{
b++;
if (flag[a][b])
{
printf("%d ", flag[a][b]);
}
}
while (a > 1 && b<n)
{
a--;
b++;
if (flag[a][b])
{
printf("%d ", flag[a][b]);
}
}
}
return 0;
}
关于这题
这里 我采用了笨办法
题目其实 除了第一个数以外 剩下的是一个循环模式
①如果能往右 往右 到头了 则往下
②斜向下
③能往下 则往下 到头了 则往右
④斜向上
我们把数组初始化为0 如果超过了 给定的范围则不打印
边栏推荐
猜你喜欢
随机推荐
回归测试如何确定测试范围
mmdetction
【面试高频题】可逐步优化的链表高频题
使用 NVIDIA Kaolin Wisp 重建3D场景
目标检测基础
openharmony容器组件之Counter
湖仓一体,Hologres加速云数据湖DLF技术原理解析
markdown学习1
SEATA分布式事务框架解析
Analysis of SEATA Distributed Transaction Framework
Firewalld防火墙基础
Three kinds of ThreadLocal, play with thread variable storage and transmission
图解LeetCode——1413. 逐步求和得到正数的最小值(难度:简单)
pyautogui的简单操作(2)-弹窗操作
Badge of openharmony container components
flink并行度知识点
C语言,if循环 for 循环 while循环 switch循环 do...while()循环
【LeetCode】1413. 逐步求和得到正数的最小值
三种ThreadLocal,玩转线程变量保存与传递
将 .json 格式 转换成 .xml格式









