当前位置: 首页 > news >正文

n阶数字回转方阵 ← 模拟法

【问题描述】
请编程输出如下数字回旋方阵。

 【算法代码】

#include <bits/stdc++.h>
using namespace std;const int maxn=100;
int z[maxn][maxn];void matrix(int n) {int num=2;z[0][0]=1;int i=0,j=1;while(i<n && j<n) {while(i<j) z[i++][j]=num++;while(j>=0) z[i][j--]=num++;i++;j=0;while(i>j) z[i][j++]=num++;while(i>=0) z[i--][j]=num++;j++;i=0;}
}int main() {int n;cin>>n;matrix(n);cout<<setw(4);for(int i=0; i<n; i++) {for(int j=0; j<n; j++)cout<<z[i][j]<<setw(4);cout<<endl;}cout<<endl;return 0;
}/*
in:
5out:1   2   9  10  254   3   8  11  245   6   7  12  2316  15  14  13  2217  18  19  20  21
*/




 

http://www.lryc.cn/news/13053.html

相关文章:

  • 【人工智能AI】二、NoSQL 基础知识《NoSQL 企业级基础入门与进阶实战》
  • Camera Rolling Shutter和Global Shutter的区别
  • 模版之AnyType
  • 【汇编】一、环境搭建(一只 Assember 的成长史)
  • 【博客628】k8s pod访问集群外域名原理以及主机开启了systemd-resolved的不同情况
  • 测试3.测试方法的分类
  • Android 基础知识4-2.9 FrameLayout(帧布局)详解
  • Go语言xorm框架
  • 19_微信小程序之优雅实现侧滑菜单
  • JSP中JDBC与javaBean学习笔记
  • 编译Android系统源码推荐的电脑配置
  • 加油站会员管理小程序实战开发教程10
  • shell编程之条件判断和流程控制
  • 第一次接触jquery
  • Vue中 引入使用 babel-polyfill 兼容低版本浏览器
  • ArcGIS Enterprise on Kubernetes 11.0安装示例
  • js 防抖函数 节流函数
  • Yarn节点unhealthy解决办法
  • 【jumpServer 功能梳理】
  • 中国各省人力资本测算就业人员受教育程度构成(2000-2021年)
  • java面试题-集合篇
  • Python 异步: 同时运行多个协程(10)
  • SVN 获取多版本间的更新内容
  • c++ const使用说明
  • VSTO 开发 EXCEL 委托与多线程的极简示例
  • spring之使用Spring的AOP
  • LeetCode LCP 66. 最小展台数量
  • 设计模式之模板方法模式
  • Python数据挖掘基础
  • Go基础-函数