首页 > 其他 > 详细

ZSTUOJ刷题④:Problem B.--输出双层金字塔

时间:2021-05-17 21:36:13      阅读:20      评论:0      收藏:0      [点我收藏+]

Problem B: 输出双层金字塔

Time Limit: 1 Sec  Memory Limit: 64 MB
Submit: 7860  Solved: 5834

Description

输出双层金字塔

Input

输入一个大于2的整数

Output

输出n层的双层金字塔

Sample Input

2
5

Sample Output

 *
***
 *
    *
   ***
  *****
 *******
*********
 *******
  *****
   ***
    *
代码如下:
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    while(cin>>n){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n-i;j++){
                cout<<" ";
            }
            for(int k=1;k<=2*i-1;k++){
                cout<<"*";
            }
            cout<<endl;
        }
        for(int i=n-1;i>=1;i--){
            for(int j=1;j<=n-i;j++){
                cout<<" ";
            }
            for(int k=1;k<=2*i-1;k++){
                cout<<"*";
            }
            cout<<endl;
        } 
    }
    
    return 0;
}

 

ZSTUOJ刷题④:Problem B.--输出双层金字塔

原文:https://www.cnblogs.com/Xuou7/p/14777553.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!