题目描述
blablabla
样例
blablabla
C++ 代码
#include<cstdio>
#include<iostream>
#include<string.h>
#include<vector>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int n;
void print(int i){
int space=(n-i)/2;
int star=i;
for (int i = 0; i < space; ++i) {
cout<<" ";
}
for (int i = 0; i < star; ++i) {
cout<<"*";
}
for (int i = 0; i < space; ++i) {
cout<<" ";
}
cout<<endl;
}
int main(){
cin>>n;
int flag=1;
int k=1;
for (int i = 1; k<=n; k++) {
print(i);
if(flag){
i=i+2;
flag=(i==n?0:1);
}
else{
i=i-2;
flag=(i==1?1:0);
}
}
return 0;
}
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度分析:blablabla
C++ 代码
blablabla