1021. 从前有座山

Description

从前有座山,山的俯视图是一个n×n

的矩形,(1,1)位置海拔最低为1

,然后海拔沿环形依次升高。

给定n的值,输出这座山的海拔高度图。

Input Format

输入仅有一行,为一个正整数n

Output Format

输出为这座山的海拔高度图。

Sample Input

4

Sample Output

     1     2     3     4
    12    13    14     5
    11    16    15     6
    10     9     8     7

Hint

首先程序#include <iomanip>

假设要输出a,将cout << a改成cout << setw(6) << a

Limits

对于20%的数据,N<10

对于100%的数据,N<150

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

#include<iostream>
using namespace std;

int main(){
    int n,i=0,j=0;
    cin>>n;
    int a[151][151]={0};
    int count=1,cishu=0;
    while(count<=n*n){
        i=cishu;
        j=cishu;
        while(j<n-cishu){
            a[i][j]=count;
            count++;
            j++;
        }
        j--;
        i++;
        while(i<n-cishu){
            a[i][j]=count;
            count++;
            i++;
        }
        i--;
        j--;
        while(j>=cishu){
            a[i][j]=count;
            count++;
            j--;
        }
        i--;
        j++;
        while(i>cishu){
            a[i][j]=count;
            count++;
            i--;
        }
        i++;
        j++;
        cishu++;
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
} 

 

转载于:https://www.cnblogs.com/bernieloveslife/p/7878616.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值