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, 100)
	}
	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
		len := 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++
				len = 1
			} else if out[nrow+dy[dir%4]][ncol+dx[dir%4]]=="#" {
				if len < 3 {
					break
				}
				dir++
				len = 1
			} else {
				row=nrow
				col=ncol
				out[row][col]="#"
				len++
			}
		}
		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 <iostream>
using namespace std;

class Guruguru
{
public:
  Guruguru(int n);
  ~Guruguru();

  void Show();

private:
  char** m_guruguru;
  int m_n;
  int m_now_i;
  int m_now_j;
  int m_direction;    //  0:上 1:右 2:下 3:左

  void make_guruguru();
  void put_point();
  void move_point();
  void change_direction();
  bool check_point();
};

Guruguru::Guruguru(int n)
{
  m_n = n;
  m_guruguru = new char*[m_n];
  for (int i=0; i<m_n; i++)
  {
    m_guruguru[i] = new char[m_n];
  }

  for (int i=0; i<n; i++)
  {
    for (int j=0; j<n; j++)
    {
      m_guruguru[i][j] = ' ';
    }
  }

  m_now_i = m_n-1;
  m_now_j = 0;
  m_direction = 0;
  make_guruguru();
}

Guruguru::~Guruguru()
{
  for (int i=0; i<m_n; i++)
  {
    delete[] m_guruguru[i];
  }
  delete[] m_guruguru;
}

void Guruguru::make_guruguru()
{
  int num = 0;
  while(true)
  {
    put_point();
    if (! check_point() )
    {
      if ( num == m_n-1 ) return;
      change_direction();
      num++;
    }
    move_point();
  }
}

void Guruguru::put_point()
{
  m_guruguru[m_now_i][m_now_j] = '#';
}

void Guruguru::move_point()
{
  switch(m_direction)
  {
  case 0:
    m_now_i--;
    break;
  case 1:
    m_now_j++;
    break;
  case 2:
    m_now_i++;
    break;
  case 3:
    m_now_j--;
    break;
  }
}

void Guruguru::change_direction()
{
  switch(m_direction)
  {
  case 3:
    m_direction = 0;
    break;
  default:
    m_direction++;
    break;
  }
}

bool Guruguru::check_point()
{
  int next_i = m_now_i;
  int next_j = m_now_j;
  int next_next_i = next_i;
  int next_next_j = next_j;
  switch(m_direction)
  {
  case 0:
    next_i--;
    next_next_i-=2;
    break;
  case 1:
    next_j++;
    next_next_j+=2;
    break;
  case 2:
    next_i++;
    next_next_i+=2;
    break;
  case 3:
    next_j--;
    next_next_j-=2;
    break;
  }
  if ( next_i < 0 || m_n <= next_i || next_j < 0 || m_n <= next_j )
  {
    return false;
  }
  else if ( next_next_i < 0 || m_n <= next_next_i || next_next_j < 0 || m_n <= next_next_j )
  {
    return true;
  }
  else
  {
    if ( '#' == m_guruguru[next_next_i][next_next_j] )
    {
      return false;
    }
    return true;
  }
}

void Guruguru::Show()
{
  for (int i=0; i<m_n; i++)
  {
    for (int j=0; j<m_n; j++)
    {
      cout << m_guruguru[i][j] << flush;
    }
    cout << endl;
  }
}

int main()
{
  int d;  //  データセットの個数
  cin >> d;
  for (int dataset=0; dataset<d; dataset++)
  {
    int n;  //  辺の長さ
    cin >> n;
    Guruguru guruguru(n);

    guruguru.Show();
    if (! dataset == d-1) cout << endl;
  }
}

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


char a[102][102];
int dx[]={ 0,1,0,-1};
int dy[]={-1,0,1,0};

int main(){
	bool fst=true;
	int n;
	cin>>n;
	while(n--){
		memset(a,' ',sizeof(a));
		int m,y,x,dir;
		cin>>m;
		y=m;x=1;dir=0;
		a[y][x]='#';
		while(1){
			for(int i=0;i<m-1;i++){
				if(a[y+2*dy[dir]][x+2*dx[dir]]=='#')break;
				y+=dy[dir];
				x+=dx[dir];
				a[y][x]='#';
			}
			dir=(dir+1)%4;
			if(a[y+2*dy[dir]][x+2*dx[dir]]=='#')break;
			if(a[y-1][x-1]=='#'||a[y-1][x+1]=='#'||a[y+1][x-1]=='#'||a[y+1][x+1]=='#')break;
		}
		for(int i=1;i<=m;i++){
			for(int j=1;j<=m;j++)cout<<a[i][j];
			cout<<endl;
		}
		if(!fst)cout<<endl;
		fst=false;
	}
	return 0;
}

C++: #include <iostream>
using namespace std;
int t,u,r,l;

char mark[100][100];
bool flag = 0;
int n;
/*
0:ツ湘」
1:ツ右
2:ツ可コ
3:ツ債カ
*/
void saiki(int x,int y,int turn){
	if(flag){
		if(n%2==0)mark[x][y]='#';
		return;
	}
	mark[x][y]='#';
	if( turn == 0 && y==t ){
		l+=2;
		if(x+1>=r){flag=1;}
		saiki(x+1,y,(turn+1)%4);
	}else if(turn == 2 && y==u ){
		r-=2;
		if(x-1<=l){flag=1;}
		saiki(x-1,y,(turn+1)%4);
	}else if(turn == 3 && x == l){
		u-=2;
		if(y-1<=t){flag=1;}
		saiki(x,y-1,(turn+1)%4);
	}else if(turn == 1 && x == r){
		t+=2;
		if(y+1>=u){flag=1;}
		saiki(x,y+1,(turn+1)%4);
	}else {
		if(turn == 0)saiki(x,y-1,turn);
		else if(turn == 1)saiki(x+1,y,turn);
		else if(turn == 2)saiki(x,y+1,turn);
		else if(turn == 3)saiki(x-1,y,turn);
	}
}

int main(){
	int c = 0;
	cin >> n;
	while(cin >> n){
		if(c++)cout << endl;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				mark[j][i]=' ';
		}
		flag = 0;
		l = t = 0;
		r = u = n-1;
		saiki(0,n-1,0);
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)
				cout << mark[j][i];
			cout << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int Tc; cin >> Tc;
  bool a = 0;
  while(Tc--) {
    int N; cin >> N;
    if(a) cout << endl;
    a = 1;
    
    char grid[N+2][N+2];
    for(int i=0; i<N; i++) {
      fill(grid[i], grid[i]+N, ' ');
      grid[i][N] = '\0';
    }

    const int dx[] = {0,1,0,-1};
    const int dy[] = {-1,0,1,0};
    
    int x = 0, y = N;
    int n = N;
    for(int i=0; i<N; i++) {
      for(int l=0; l<n; l++) {
	y += dy[i%4], x += dx[i%4];
	grid[y][x] = '#';
      }
      if(i%2 == 0 && i>=2) n -= 2;
      if(i%4 == 0) x --;
      if(i%4 == 1) y --;
      if(i%4 == 2) x ++;
      if(i%4 == 3) y ++;
    }
    
    for(int i=0; i<N; i++) {
      cout << grid[i] << endl;
    }
  }
  
  return 0;
}

C++: #include <iostream>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
bool isOk(int i, int r, int c, bool b[104][104]) {
	if(i%2==0) {
		if(b[r][c-1]==0&&b[r][c+1]==0) {
			if(i==0?b[r-1][c]==0:b[r+1][c]==0) return true;
		}
	} else {
		if(b[r-1][c]==0&&b[r+1][c]==0) {
			if(i==1?b[r][c+1]==0:b[r][c-1]==0) return true;
		}
	}
	return false;
}
int main() {
	int n, a;
	cin >> n;
	rep(i,n) {
		cin >> a;
		bool b[100+4][100+4] = {};
		rep(i,a+4) {
			b[i][0] = 1;
			b[i][a+3] = 1;
			b[0][i] = 1;
			b[a+3][i] = 1;
		}
		int r = a+1, c = 2, cnt = 0;
		while(1) {
			if(!isOk(cnt, r, c, b)) break;
			while(isOk(cnt, r, c, b)) {
				b[r][c] = 1;
				switch(cnt) {
				case 0: r--;
					break;
				case 1: c++;
					break;
				case 2: r++;
					break;
				case 3: c--;
					break;
				}
			}
			cnt = (cnt+1) % 4;
			switch(cnt) {
				case 0: r--, c++;
					break;
				case 1: c++, r++;
					break;
				case 2: r++, c--;
					break;
				case 3: c--, r--;
					break;
			}
		}
		rep2(i,2,a+2) {
			rep2(j,2,a+2) {
				cout << (b[i][j] ? "#": " ");
			}
			cout << endl;
		}
	}
	return 0;
}