時間限制:C/C++ 1秒,其他語言2秒 空間限制:C/C++ 32768K,其他語言65536K 64bit IO Format:%lld
題目描述
輸出雙層金字塔。
輸入描述:
多個測試數據。每個測試數據輸入一個整數n( 2 <= n <= 9)
輸出描述:
輸出雙層金字塔
鏈接:https://ac.nowcoder.com/acm/problem/22204
來源:牛客網
示例1
輸入
> 2
> 5
輸出
*
***
*
*
***
*****
*******
*********
*******
*****
***
*
#include<iostream>
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 j=1;j<=2*i-1;j++)
{
cout<<"*";
}
cout<<endl;
}
for(int i=1;i<n;i++)
{
for(int j=n-1;j>=n-i;j--)
{
cout<<" ";
}
for(int j=2*(n-1)-1;j>=2*i-1;j--)
{
cout<<"*";
}
cout<<endl;
}
}
return 0;
}