15 条题解
-
5许栋轶 LV 10 @ 2023-1-31 17:02:43
将三角形的每行拆开,找规律
以样例为例子:
第一行:两个空格一个*
第二行:一个空格三个*
第三行:零个空格五个*
空格变化:2, 1, 0
规律:从 n-1 往下递减1,直到0
*号变化:1, 3, 5
规律:从 1 往下递增2,加 n - 1 次(第一次是1)
#include <iostream> #include <stack> #include <cmath> #include <vector> #include <string.h> #include <queue> #include <stdio.h> #include <iomanip> #include <cstdio> #include <algorithm> #define int long long using namespace std; const int N = 1e5 + 10; signed main() { int n; cin >> n; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n - i; j++)//求左边的空格数 { cout << " "; } for(int j = 1; j <= 1 + (i - 1) * 2; j++)//求*数 { cout << "*"; } puts(""); } }
-
12023-6-19 16:43:13@
#include <iostream> #include <stack> #include <cmath> #include <vector> #include <string.h> #include <queue> #include <stdio.h> #include <iomanip> #include <cstdio> #include <algorithm> #define int long long using namespace std; const int N = 1e5 + 10; signed main() { int n; cin >> n; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n - i; j++) { cout << " "; } for(int j = 1; j <= 1 + (i - 1) * 2; j++) { cout << "*"; } cout << endl ; } } ////////////////////////////////
-
12023-4-12 19:40:49@
using namespace std; const int N = 1e5 + 10; int n; int main(){ cin >> n; for ( int i = 1; i<= n; i++) { for ( int j=1 ; j <= n - i; j++) { cout << " "; } for ( int j=1 ; j <= 2*i-1; j++) { cout << "*"; } cout << endl; } return 0; }
-
12023-3-19 18:43:02@
#include<bits/stdc++.h>; using namespace std; int n; int main() { cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n+i-1;j++){ if(n-i+1<=j&&n+i>=j)cout<<"*"; else cout<<" "; } cout<<endl; } }
-
12022-12-11 17:23:43@
#include<bits/stdc++.h>;
using namespace std; int main() { int n; cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n+i-1;j++){ if(n-i+1<=j&&n+i>=j)cout<<"*"; else cout<<" "; } cout<<endl; } }
-
02024-11-18 22:16:21@
#include <bits/stdc++.h> using namespace std; int n,sum; int main() { cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n-i;j++)cout<<" "; for(int j=1;j<=i+sum;j++){ cout<<"*"; } sum++; cout<<endl; } return 0; }
-
02023-12-24 17:59:33@
int a; cin>>a; for(int i=1;i<=a;i++){ for(int j=1;j<=a-i;j++){ cout<<" "; } for(int j=1;j<=1+(i-1)2;j++){ cout<<""; } cout<<endl; }
-
02023-12-24 17:58:31@
#include <iostream> #include <stack> #include <cmath> #include <vector> #include <string.h> #include <queue> #include <stdio.h> #include <iomanip> #include <cstdio> #include <algorithm> #define int long long using namespace std; const int N = 1e5 + 10; signed main() { int n; cin >> n; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n - i; j++)//求左边的空格数 { cout << " "; } for(int j = 1; j <= 1 + (i - 1) * 2; j++)//求*数 { cout << "*"; } puts(""); } }
-
02023-12-24 17:56:13@
#include <iostream> #include <stack> #include <cmath> #include <vector> #include <string.h> #include <queue> #include <stdio.h> #include <iomanip> #include <cstdio> #include <algorithm> #define int long long using namespace std; const int N = 1e5 + 10; signed main() { int n; cin >> n; for(int i = 1; i <= n; i++) { for(int j = 1; j <= n - i; j++)//求左边的空格数 { cout << " "; } for(int j = 1; j <= 1 + (i - 1) * 2; j++)//求*数 { cout << "*"; } puts(""); } }
-
02023-6-2 20:02:01@
#include <iostream> #include <bits/stdc++.h> using namespace std; const int N=1e7+10; const int INF=0x3f3f3f3f; int main() { int a,bu; cin>>a; bu=2*a-1; int g=0,z=bu/2+1; for(int i=1;i<=a;i++) { for(int j=1;j<=bu;j++) { if(j<=z+g && j>=z-g) { cout<<'*'; } else { cout<<' '; } } cout<<endl; g++; } }
-
02023-4-12 19:42:25@
#include<iostream> using namespace std; int n; int main(){
cin >> n; for(int i = 1;i <= n;i++) { for(int j = 1;j <= n - i;j++) { cout << " "; } for(int j = 1;j <= 2*i - 1;j++) { cout << "*"; } cout << endl;
}
return 0;
}
-
02023-4-12 19:37:06@
#include <bits/stdc++.h> using namespace std; int n; int main() { cin>>n; for(int i=1;i<=n;i++) { for(int j=1;j<=n-i;j++) { cout<<" "; } for(int j=1;j<=2*i-1;j++) { cout<<"*"; } cout<<endl; } return 0; }
-
02022-2-12 11:17:00@
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<string.h>
#include<algorithm>
using namespace std; int main() {
int n; cin>>n; for(int i=1;i<=n;i++) { for(int j=1;j<=n+i-1;j++) { if(n-i+1<=j&&n+i>=j) cout<<"*"; else cout<<" "; } cout<<endl; }
}
-
-12023-7-9 9:58:18@
#include<iostream> using namespace std; int n; int main(){ cin>>n; for(int i=1;i<=n;i++) { for(int j=1;j<=n-i;j++) { cout<<" "; } for(int j=1;j<=i*2-1;j++) { cout<<"*"; } cout<<endl; } return 0; }
-
-12022-2-12 11:18:35@
#include <iostream> #include <stdio.h> using namespace std; int main () { int n; cin >> n; for (int i = 1 ; i <= n ; i ++) { for (int j = 1 ; j <= n + i - 1 ; j ++) { if (n - i + 1 <= j && n + i >= j) cout << "*"; else cout << " "; } cout << endl; } }
- 1
信息
- ID
- 954
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- 递交数
- 687
- 已通过
- 288
- 上传者