#38383: 是否測資有問題?


hshua (hshua)


#include <bits/stdc++.h>
using namespace std;
int K,a[505][500*4+5]={};
//------------------------------
void prt(int cmax){
    for(int r=0; r<K; r++){
        for(int c=0; c<=cmax; c++)
            cout<<(a[r][c]==1 ? '*' : ' ');
        cout<<endl;
    }   
}
//------------------------------
int main() {
    cin>>K;
    memset(a,0,sizeof(a));
    int r=K/2, c=0;
    for(int i=0; i<K; i++) a[r][c++]=1;
    int tmp=(K%2==0 ? K/2 : K/2+1);
    c--;
    for(int i=1; i<tmp; i++){ 
        r++, c++;
        a[r][c]=1;
    } 
    for(int i=1; i<K; i++){ 
        r--, c++;
        a[r][c]=1;
    }
    for(int i=1; i<(K*2); i++){ 
        c++;
        a[r][c]=1;
    }
    prt(c);
}    

#38386: Re: 是否測資有問題?


wilson40804@apps.ntpc.edu.tw (廖偉丞)


https://zerojudge.tw/ShowThread?postid=38387&reply=38380#38387