1 solutions

  • 0
    @ 2024-10-15 14:47:22

    就直接模拟输出注意对齐和空格

    #include<bits/stdc++.h>
    typedef long long LL;
    using namespace std;
    
    int main ()
    {
    	int n,n1,n2;
    	char c = '*';
    	cin >> n;
    	n1 = (n + 1) / 2;
    	n2 = n / 2;
    	for(int i = 1;i <= n1;++ i)//上层 
    	{
    		for(int j = 1;j < i;++ j)
    		{
    			cout << " ";//打印空格 
    		}
    		for(int j = 1;j <= (n1 - i) * 2 + 1;++ j)
    		{
    			cout << c;
    		}
    		cout << "\n"; 
    	}
        for(int i = 1;i <= n2;++ i)//下层 
        {
            for (int j = 1; j < n2 - i + 1;++ j)
                cout << " ";
            for (int j = 1; j <= 2 * i + 1; j++)
                cout << c;
            cout << "\n";
        }
    	
    	return 0;
    }
    

    Information

    ID
    414
    Time
    1000ms
    Memory
    16MiB
    Difficulty
    5
    Tags
    # Submissions
    82
    Accepted
    34
    Uploaded By