当前位置:网站首页>*4-2 CCF 2014-12-2 zigzag scan
*4-2 CCF 2014-12-2 zigzag scan
2022-08-09 14:51:00 【Ye Xiaobai】
题目描述

样例

源代码
#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;
}
关于这题
这里 I took a stupid approach
topic actually except for the first number The rest is a loop pattern
①If you can go right 往右 到头了 则往下
②斜向下
③can go down 则往下 到头了 则往右
④斜向上
我们把数组初始化为0 如果超过了 The given range is not printed
边栏推荐
- How to adjust the spacing between numbers and text in Word?
- 青蛙跳台阶
- *1-1 OJ 56 Hamming Distance
- Jetpack Compose - Image using Coli load network Image (including GIF, SVG)
- dpkg:错误:无法新建文件 ‘/var/lib/dpkg/info/format-new’: 没
- apt-cache command
- [Video coding learning] - understanding of transformation
- The RHCE course summary
- 阿里云发布中国云原生数据湖应用洞察白皮书
- *1-1 OJ 56 Hamming Distance
猜你喜欢
随机推荐
RHCE课程总结
Jetpack Compose - remember, mutableStateOf, rememberSaveable
Assembly language learning (9)
shell课程总结
青蛙跳台阶
*1-2 OJ 190 游程编码
Difference between apt-get install and pip install
iptables之SNAT与DNAT
小程序程序开发怎么做?应以突出功能为主
apt-get install 和pip install 的区别
RHCE Course Summary
From the Dutch flag problem to the optimization and upgrade of quick row
Es7.x使用RestHighLevelClient进行增删改和批量操作
word编号和文本间距过大
Shell course summary
除了开心麻花,中国喜剧还有什么?
*3-4 CCF 2014-09-3 字符串匹配
预约直播 I 阿里云EMR StarRocks 产品发布会
RHCE课程总结
C语言中的 pow 函数 使用方法及注意事项,和常见报错原因,且分享实战中的使用









