code/sha_lou.cpp

40 lines
574 B
C++

//沙漏
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin >>n;
int mid = (n - 1) / 2;
for (int i = 0; i < n; i++)
{
int a,b;
if (i <= mid)
{
a = i;
b = n - 2 *i;
}else
{
int j = 2 * mid - i;
a = j;
b = n -2 *j;
}
for (int j = 0; j < a; j++)
{
cout <<" ";
}
for (int y = 0; y < b; y++)
{
cout <<"*";
}
cout <<endl;
}
return 0;
}