Printing numbers in a pyramid pattern(一)

Description
Write a program that reads an interger n, then display one of the following patterns.
Pattern 1
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

Pattern 2
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Pattern 3
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

Pattern 4
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1

Input
An integer n (1<=n<=4).

Output
Pattern n.
You should specify the width of each number’s print field to 3, justify the output to right.

Sample Input
Copy sample input to clipboard
1
Sample Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6

代码实现:

#include<iostream>
using namespace std;

void  fun1(int rows)
{
    for(int i = 1; i <= rows; i++){
        for(int j = 1; j <= i; j++){
            cout << "  " << j;   //两个空格
        }
        cout << endl;
    }
}

void fun2(int rows)
{
    for(int i = rows; i >= 1; i--){
        for(int j = 1; j <= i; j++){
            cout << "  " << j;    //两个空格
        }
        cout << endl;
    }
}

void fun3(int rows)
{
    for(int i = rows; i >= 1; i--){
        for(int j = 0; j < i-1; j++){
            cout << "   ";  //三个空格 
        }
        for(int j = 1; j <= (rows+1)-i; j++){
            cout << "  " << j;  //两个空格 
        }
        cout << endl;
    }
}

void fun4(int rows)
{
    for(int i = 1; i <= rows; i++){
        for(int j = 0; j < i-1; j++){
            cout << "   ";
        }
        for(int j = 1; j <= (rows+1)-i; j++){
            cout << "  " << j;
        }
        cout << endl;
    }   
} 


int main()
{
    int n;
    while(cin >> n){
        switch(n){
            case 1: fun1(6); break;
            case 2: fun2(6); break;
            case 3: fun3(6); break;
            case 4: fun4(6); break; 
        }
    }
    return 0;
}
Pyramid Vision Transformer (PVT)是一种用于密集预测的通用backbone,它是一种基于Transformer的设计。PVT的整体架构包括了Transformer编码器和其他细节。PVT的设计使得它可以应用于图像分类、目标检测和实例分割等任务。 PVT的整体架构包括了Transformer编码器和其他细节。Transformer编码器是PVT的核心组件,它通过自注意力机制和全连接层来建模输入图像的关系。PVT还采用了金字塔结构,通过在不同尺度上应用Transformer来捕捉图像中的多尺度信息。这种金字塔结构可以提高PVT在密集预测任务中的性能。 PVT还提供了相应的代码实现,包括了图像分类、目标检测和实例分割的代码。这些代码可以帮助研究人员和开发者更好地理解和应用PVT模型。 论文地址:PVT-V1版本论文 源码地址:PVT-v1-torch源码<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [PVT论文精读:Pyramid Vision Transformer: A Versatile Backbone for Dense Predictionwithout ...](https://blog.csdn.net/qq_52053775/article/details/127700540)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [Pyramid Vision Transformer (PVT) 代码,用于密集预测的通用backbone](https://download.csdn.net/download/weixin_42715977/87625056)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [Pyramid Vision Transformer: A Versatile Backbone for Dense Prediction without Convolutions论文以及...](https://blog.csdn.net/m0_45971439/article/details/120495124)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值