2 solutions

  • 0
    @ 2026-8-7 18:45:56
    #include<bits/stdc++.h>
    using namespace std;
    int main(){
        int n;
        cin>>n;
        int half=(n+1)/2; 
        for(int i=1;i<=half;i++){
            for(int j=1;j<=half-i;j++){
                cout<<".";
            }
            int len=2*i-1;
            for(int k=1;k<=len;k++){
                if(k==1||k==len){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }
            for(int j=1;j<=half-i;j++){
                cout<<".";
            }
            cout<<endl; 
        }
        for(int i=half-1;i>=1;i--){
            for(int j=1;j<=half-i;j++){
                cout<<".";
            }
            int len=2*i-1;
            for(int k=1;k<=len;k++){
                if(k==1||k==len){
                    cout<<"#";
                }else{
                    cout<<".";
                }
            }
            for(int j=1;j<=half-i;j++){
                cout<<".";
            }
            cout<<endl; 
        }
        return 0;
    }
    
    

    Information

    ID
    46
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    6
    Tags
    # Submissions
    24
    Accepted
    12
    Uploaded By