#include<bits/stdc++.h> using namespace std; int main(){ int n,i,j,s=0; char a; cin>>n>>a; int m=int(sqrt(double(n+1)/2));//算行数的公式,减少循环 int f=2*m-1; for( i=0;i<m;i++){ for( j=0;j<i;j++)cout<<" "; for(j=0;j<f-2*i;j++){cout<<a;s++;} cout<<endl; } for(i=m-2;i>=0;i--){ for(j=0;j<i;j++)cout<<" "; for(j=0;j<f-2*i;j++){cout<<a;s++;} cout<<endl; } cout<<n-s; }
标签:std,沙漏,int,double,打印,main From: https://www.cnblogs.com/zhengmou/p/17334535.html