Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	out := make([][]string, 100)
	for i := range out {
		out[i] = make([]string, 101)
	}
	dx := []int{0, 1, 0, -1}
	dy := []int{-1, 0, 1, 0}
	scanner.Scan()
	a, _ := strconv.Atoi(scanner.Text())
	for a > 0 {
		a--
		scanner.Scan()
		b, _ := strconv.Atoi(scanner.Text())
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				out[i][j] = " "
			}
			out[i][b] = "0"
		}
		if b == 1 {
			fmt.Println("#")
			if a != 0 {
				fmt.Println()
			}
			continue
		}
		if b == 2 {
			fmt.Println("##")
			if a != 0 {
				fmt.Println()
				continue
			}
		}
		row := b -1
		col := 0
		dir := 0
		l := 0
		out[row][col] = "#"
		for {
			nrow := row+dy[dir%4]
			ncol := col+dx[dir%4]
			if dir%4 == 0 && nrow == 0 || dir%4==3&&ncol==0 || dir%4==2&&nrow==b-1 || dir%4==1&&ncol==b-1 {
				row=nrow
				col=ncol
				out[row][col]="#"
				dir++
				l = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if l < 3 {
					break
				}
				dir++
				l = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				l++
			}
		}
		for i := 0; i < b; i++ {
			for j := 0; j < b; j++ {
				fmt.Printf("%s", out[i][j])
			}
			fmt.Println()
		}
		if a != 0 {
			fmt.Println()
		}
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

int n;
int input(){
  if(cin>>n)return true;
  return false;
}

vector<string> ans;
void solve(){
  ans.resize(n);
  for(int i=0;i<ans.size();i++){
    ans[i]="";
    for(int j=0;j<n;j++){
      ans[i] += " ";
    }
  }
  int x=0;
  int y=0;
  int d=0;
  int m=n+2;
  const int dx[] = {1,0,-1,0};
  const int dy[] = {0,1,0,-1};
  for(int i=0;i<n;i++){
    for(int j=0;j<min(m-1,n-1);j++){
      ans[x][y]='#';
      x += dx[d];
      y += dy[d];
      ans[x][y]='#';
    }
    d=(d+1)%4;;
    if(d%2){
      m-=2;
    }
  }
  ans = vector<string>(ans.rbegin(),ans.rend());
}

void print(){
  for(auto i:ans){
    cout<<i<<endl;
  }
}


int main(){
  int j = false;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    input();
    if(j)cout<<endl;
    j=true;
    solve();
    print();
  }
}

C++: #include<iostream>
using namespace std ;

int N ;
int dx[] = {0,1,0,-1} ;
int dy[] = {-1,0,1,0} ;

void func(){
	char table[102][102] ;
	
	for( int i=0 ; i<102 ; i++ ){
		for( int j=0 ; j<102 ; j++ ){
			if( i>=100-N && i<=100 && j>=1 && j<=N ) table[i][j] = '#' ;
			else table[i][j] = ' ' ;
		}
	}
	
	int x = 1   ;
	int y = 100 ;
	int k = 0 ;
	bool f = true ;
	
	while(1){
		if( table[y+dy[k%4]][x+dx[k%4]] == ' ' ) break ;
		bool b = false ;
		while( table[y+dy[k%4]][x+dx[k%4]] != ' ' ){
			if( f || b ) table[y+dy[(k+1)%4]][x+dx[(k+1)%4]] = ' ' ;
			if( !b ) b = true  ;
			if(  f ) f = false ;
			x += dx[k%4] ;
			y += dy[k%4] ;
		}
		k++ ;
	}
	
	for( int i=100-N ; i<=100 ; i++ ){
		for( int j=1 ; j<=N ; j++ ){
			cout << table[i][j] ;
		}cout << endl ;
	}
}

int main(){
	
	int d ;
	
	cin >> d ;
	while( d-- ){
		cin >> N ;
		func() ;
		cout << endl ;
	}
	
return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
//#include <map>
#include <set>
#define INF (1000000000)
#define MOD (1000000007)
#define K (2)
using namespace std;

typedef vector<int> VI;
typedef vector<int>::iterator VII;
typedef vector<double> VD;
typedef vector<double>::iterator VDI;
typedef pair<int, int> PII;


char map[200][200];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

int main()
{
	int num;
	scanf("%d", &num);
	for (int ca = 0; ca < num; ca++){
		for (int i = 0; i < 200; i++){
			strcpy(map[i], "");
		}
		
		int n;
		scanf("%d", &n);
		
		for (int i = 0; i < n + K + K; i++){
			for (int j = 0; j < n + K + K; j++){
				if (!i || !j || i == n + K + K - 1 || j == n + K + K - 1){
					map[i][j] = '#';
				}
				else {
					map[i][j] = ' ';
				}
			}
		}
		
		int y = n - 1 + K;
		int x = K;
		int d = 0;
		int nodraw = 0;
		while (true){
			int b = (d + 2) % 4;
			int r = (d + 1) % 4;
			if (map[y + dy[b]][x + dx[b]] != '#' || map[y + dy[r]][x + dx[r]] != '#'){
				map[y][x] = '#';
			}
			else {
				break;
			}
						
			if (map[y + dy[d] * 2][x + dx[d] * 2] == '#'){
				d = (d + 1) % 4;
				if (++nodraw == 4){
					break;
				}
			}
			else {
				y += dy[d];
				x += dx[d];
				nodraw = 0;
			}
		}
		
		if (ca) puts("");
		for (int i = 2; i < n + K; i++){
			printf("%.*s\n", n, &map[i][2]);
		}
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>

/*
 
#####
#   #
# # #
# # #
# ###

######
#    #
# ## #
# #  #
# #  #
# ####
 
*/
using namespace std;



void f(char guruguru[100][100], int l, int d, int x, int y){
    
    if(l<=0)return;
    
    if(d==0){//右下
        for(int i=0; i<l; i++){
            guruguru[y][x+i]='#';
        }
        x=x+(l-1);
        
        if(l==2)return;
        
        for(int i=0; i<l; i++){
            guruguru[y+i][x]='#';
        }
        y=y+(l-1);
        l=l-2;
        d=1;
        f(guruguru,l,d,x,y);
    }
    
    if(d==1){//左上
        
        
        for(int i=0; i<l; i++){
            guruguru[y][x-i]='#';
        }
        x=x-(l-1);
        
        if(l<=2)return;
        
        for(int i=0; i<l; i++){
            guruguru[y-i][x]='#';
        }
        y=y-(l-1);

        l=l-2;
        d=0;
        f(guruguru,l,d,x,y);
    }

}

void f0(char guruguru[100][100], int l, int d, int x, int y){
    for(int i=0; i<l; i++){
        guruguru[i][0]='#';
    }
    
    f(guruguru,l,0,0,0);
}

int main(){
    char init[100][100];
    for(int i=0; i<100; i++){
        for(int j=0; j<100; j++){
            init[i][j]=' ';
        }
    }
    int n;
    cin>>n;
    for(int roop=0; roop<n; roop++){
        int l;
        cin>>l;
        char guruguru[100][100];
        memcpy(guruguru,init,sizeof(init));
        
        f0(guruguru,l,0,0,0);
        
        for(int i=0; i<l; i++){
            for(int j=0; j<l; j++){
                cout<<guruguru[i][j];
            }
            cout<<endl;
        }
        cout<<endl;
    }
}