Untitled

mail@pastecode.io avatar
unknown
c_cpp
2 years ago
870 B
7
Indexable
Never
//Spiral
#include <stdio.h>
int main(){

    int t, posi = 0, posj = -1, dirct = 0, n;
    int di[4] = {0, 1,0 ,-1};
    int dj[4] = {1, 0,-1, 0};

    scanf("%d",&t);

    while(t > 0){

        char map[5005][5005] = {' '};
        int posi = 0; posj = -1, dirct = 0;
        scanf("%d", &n);
        int tmp = n;

        while(n > 0){
            for(int i = 1; i <= n; i++){
                map[posi + di[dirct]*i][posj + dj[dirct]*i] = '#';
            }
            posi += di[dirct]*n;
            posj += dj[dirct]*n;
            dirct = (dirct + 1) % 4;
            n--;
        }
        
        for(int i = 0; i < tmp; i++){
            for(int j = 0; j < tmp; j++){
                if(map[i][j] == '#') printf("#");
                else printf(" ");
            }
            printf("\n");
        }
        t--;
    }
}