Example 2.2 倒蛇阵填数
来源:互联网 发布:怎样应对网络安全问题 编辑:程序博客网 时间:2024/06/08 07:21
</pre><pre name="code" class="cpp">
/* * main.cpp * * Created on: 2014年9月13日 * Author: xiangxiyun * * Description: 倒蛇阵填数 * * Example: when N = 4 * Output: 10 11 12 1 * 9 16 13 2 * 8 15 14 3 * 7 6 5 4 */#include <iostream>using namespace std;int main() {int n = 0, i = 0, r = 1;cin >> n;int number[n][n];//initalizefor(int i = 0; i < n; i++) {for(int j = 0; j < n; j++) {number[i][j] = 0;}}while(i < n - 1 -i) {//from upright to downrightfor(int j = i; j < n-i; j++) {number[j][n-i-1] = r;r++;}//from downright to downleftfor(int j = n-i-2; j >=i; j--) {number[n-i-1][j] = r;r++;}//from downleft to upleftfor(int j = n-i-2; j>=i; j--){number[j][i] = r;r++;}//from upleft to uprightfor(int j = i+1; j <= n-i-2; j++) {number[i][j] = r;r++;}i++;}//terminateif(i == n-i-1) {number[i][i] = n*n;}//outputfor(int i = 0; i < n; i++) {for(int j = 0; j < n; j++) {cout << number[i][j] << ' ';}cout << '\n';}return 0;}
0 0
- Example 2.2 倒蛇阵填数
- example
- example
- Example
- example
- Example
- Example
- Example
- Example
- example
- Example
- Example
- Maven by Example 2.2. Downloading Maven
- TDD example
- CreateJobObject example
- tex example
- CreateThread example
- CreateJobObject example
- 【Hdu】Minimum Inversion Number(逆序,线段树)
- SQL删除重复数据只保留一条
- java IO字节流
- Mac OS使用技巧之十:Finder的详细使用方法
- 银行卡安全密码算法辅助计算工具(3DES+RSA)
- Example 2.2 倒蛇阵填数
- tcp服务器编程
- kbengine下载
- Linux网络编程:原始套接字编程(上)
- iptables
- uva 11100(贪心)
- windows下搭建python&opencv3.0环境
- 2014鞍山网络赛 E题||hdu 5001 概率dp
- LeetCode——Trapping Rain Water