CCF—Z字形扫描 20141202
来源:互联网 发布:linnx远程桌面端口开启 编辑:程序博客网 时间:2024/06/18 16:43
#include <iostream>
using namespace std;
//向右移动0 向右上移动1 向下移动2 向左下移动3
int main()
{
int n,A[500][500];
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)cin >> A[i][j];
int row = 0, col = 0;
int temp=0;
while (row != n - 1 || col != n - 1)
{
cout << A[row][col] << ' ';
switch (temp)
{
case 0:
col++;
if (row == 0) temp = 3;
else temp = 1;
break;
case 1:
row--;
col++;
if (row == 0 && col != n - 1)temp = 0;
else if (col == n - 1)temp = 2;
else temp = 1;
break;
case 2:
row++;
if (col == 0)temp = 1;
else temp = 3;
break;
case 3:
row++;
col--;
if (col == 0 && row != n - 1) temp = 2;
else if (row == n - 1) temp = 0;
else temp = 3;
break;
}
}
cout << A[n - 1][n - 1];//保证最后一个元素输出来
}
using namespace std;
//向右移动0 向右上移动1 向下移动2 向左下移动3
int main()
{
int n,A[500][500];
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)cin >> A[i][j];
int row = 0, col = 0;
int temp=0;
while (row != n - 1 || col != n - 1)
{
cout << A[row][col] << ' ';
switch (temp)
{
case 0:
col++;
if (row == 0) temp = 3;
else temp = 1;
break;
case 1:
row--;
col++;
if (row == 0 && col != n - 1)temp = 0;
else if (col == n - 1)temp = 2;
else temp = 1;
break;
case 2:
row++;
if (col == 0)temp = 1;
else temp = 3;
break;
case 3:
row++;
col--;
if (col == 0 && row != n - 1) temp = 2;
else if (row == n - 1) temp = 0;
else temp = 3;
break;
}
}
cout << A[n - 1][n - 1];//保证最后一个元素输出来
}
阅读全文
0 0
- CCF—Z字形扫描 20141202
- 【CCF】Z字形扫描
- ccf Z字形扫描
- CCF Z字形扫描
- CCF Z字形扫描
- ccf Z字形扫描
- ccf-Z字形扫描
- 【CCF】Z字形扫描
- CCF Z字形扫描
- CCF题目:Z字形扫描
- CCF之Z字形扫描
- CCF真题——Z字形扫描(java)
- Z字形扫描-CCF测试往届题
- ccf认证试题 Z字形扫描
- CCF 201412-2Z字形扫描 题解
- ccf-201412-2 Z字形扫描
- ccf Z字形扫描 30行版
- CCF-201412-2 Z字形扫描
- 2015 三大运营商换帅
- (剑指offer)正则表达式匹配
- MySQL中的约束,添加约束,删除约束,
- 处理org.apache.hadoop.hbase.client.ScannerTimeoutException
- 顺序表应用5:有序顺序表归并
- CCF—Z字形扫描 20141202
- 全球的经济数据
- android 多媒体总结--音频相关(一)
- 接口默认方法冲突
- Android Notification自定义通知样式你要知道的事
- Nginx location块匹配顺序
- error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCR...
- CCF—画图 20140902
- 第二周项目3体验复杂度