1 条题解

  • 1
    @ 2026-9-2 20:53:30
    #include <bits/stdc++.h>
    using namespace std;
    int n;
    
    int main() {
    	cin >> n;
    	for (int i = 1; i <= n - 1; i++) {
    		cout << ' ';
    	}
    	for (int i = 1; i <= n; i++) {
    		cout << '*';
    	}
    	cout << '\n';
    	for (int i = 1; i <= n - 1; i++) {
    		for (int j = 1; j <= n - 1 - i; j++) {
    			cout << ' ';
    		}
    		cout << '*';
    		for (int j = 1; j <= n - 1 + i * 2 - 1; j++) {
    			cout << ' ';
    		}
    		cout << '*' << '\n';
    	}
    	for (int i = n - 2, x = 1; i >= 1; i--, x++) {
    		for (int j = 1; j <= x; j++) {
    			cout << ' ';
    		}
    		cout << '*';
    		for (int j = 1; j <= n - 1 + i * 2 - 1; j++) {
    			cout << ' ';
    		}
    		cout << '*' << '\n';
    	}
    	for (int i = 1; i <= n - 1; i++) {
    		cout << ' ';
    	}
    	for (int i = 1; i <= n; i++) {
    		cout << '*';
    	}
    	return 0;
    }
    
    
    

    点个赞吧!😘

    信息

    ID
    30015
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    8
    已通过
    5
    上传者