1 条题解
-
0
C :
#include <stdio.h> void main () { int n; scanf("%d",&n); int i; for ( i = 1; i<=n; i++ ) { if(i<=n-1) { int k; for(k=1; k<=n-i; k++) { printf(" "); } printf("*"); int j; for(j=1; j<=2*i-3; j++) { printf(" "); } if( i-1!=0 ) { printf("*"); } printf("\n"); } if(i==n) { int x; for( x=1; x<=2*n-1; x++ ) { printf("*"); } } } }
C++ :
#include <iostream> using namespace std; int main(){ int i,j,n; cin>>n; for(i = 1;i <= n;i++){ for(j = 1;j <= n - i;j++){ cout<<" "; } for(j = 1;j <= 2 * i - 1;j++){ if(i == 1){ cout<<"*"; }else if(i == n){ cout<<"*"; }else{ if(j != 1 && j != 2 * i - 1){ cout<<" "; }else{ cout<<"*"; } } } cout<<endl; } }
Python :
n = int(input()) i = 1 while i <= n: j = 1 while j <= n - i: print(" ",end="") j += 1 k = 1 while k <= 2*i-1: if k == 1 or k == 2*i-1 or i == n: print("*",end="") else: print(" ",end="") k += 1 print("") i += 1
- 1
信息
- ID
- 2157
- 时间
- 1000ms
- 内存
- 16MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者