6 solutions
-
0
#include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; int temp=n-2; //上半部分n行 for(int i=1;i<=n;i++) { //n为1 if(n==1) { cout<<"*"; break; } //左侧空格 for(int j=n-i;j>=1;j--) { cout<<" "; } //顺带输出 cout<<"*"; //中间 for(int k=temp;k>=1;k--) { //首行输出*,否则输出空格 if(i==1) cout<<"*"; else cout<<" "; } //顺带输出 cout<<"*"<<endl; //循环次数自增2 temp+=2; } //下半部分n-1行 n--; temp-=2; for(int i=1;i<=n;i++) { temp-=2; for(int j=1;j<=i;j++) { cout<<" "; } cout<<"*"; for(int k=temp;k>=1;k--) { if(i==n) cout<<"*"; else cout<<" "; } cout<<"*"<<endl; } return 0; }
Information
- ID
- 66
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 3
- Tags
- (None)
- # Submissions
- 73
- Accepted
- 35
- Uploaded By