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.Printf("##\n# \n")
			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<iostream>
using namespace std;

#define MAX_N 300

int x[MAX_N][MAX_N];
int n, a, cx, cy, cnt;

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

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cnt = 0;
		cin >> a;
		for (int j = 0; j < MAX_N; j++) {
			for (int k = 0; k < MAX_N; k++) {
				x[j][k] = 0;
			}
		}
		cx = 0; cy = a - 1;
		x[cy][cx] = 1;
		while (cnt < a) {
			while (true) {
				int Y1 = cy + dy[cnt % 4];
				int X1 = cx + dx[cnt % 4];
				int Y2 = cy + dy[cnt % 4] * 2;
				int X2 = cx + dx[cnt % 4] * 2;
				if (Y1 >= 0 && Y1 < a && X1 >= 0 && X1 < a) {
					if (Y2 >= 0 && Y2 < a && X2 >= 0 && X2 < a) {
						if (x[Y2][X2] == 1) {
							break;
						}
					}
				}
				else {
					break;
				}
				cx = X1; cy = Y1;
				x[cy][cx] = 1;
			}
			cnt++;
		}
		for (int j = 0; j < a; j++) {
			for (int k = 0; k < a; k++) {
				if (x[j][k] == 1) {
					cout << '#';
				}
				else {
					cout << ' ';
				}
			}
			cout << endl;
		}
	}
}

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

int t,n,y,x,d,f;
char c[N][N];
int dy[4]={1,0,-1,0};
int dx[4]={0,1,0,-1};

bool check(int a,int b){
  return (a>=0&&b>=0&&a<n&&b<n);
}

int main(){
  cin>>t;
  while(t--){
    cin>>n;
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)c[i][j]=' ';
    y=x=d=0;
    c[y][x]='#';
    while(1){
      int ny=y+dy[d];
      int nx=x+dx[d];
      f=0;
      if(ny<0||nx<0||n<=ny||n<=nx)f=1;
      int a=ny+dy[d],b=nx+dx[d];
      if(check(a,b)&&c[a][b]=='#')f=1;
      if(f)d=(d+1)%4;
      ny=y+dy[d];
      nx=x+dx[d];
      a=ny+dy[d],b=nx+dx[d];
      if(check(a,b)&&c[a][b]=='#')break;
      a=ny+dy[(d+1)%4],b=nx+dx[(d+1)%4];
      if(check(a,b)&&c[a][b]=='#')break;
      y+=dy[d];
      x+=dx[d];
      c[y][x]='#';
    }
    for(int i=n-1;i>=0;i--){
      for(int j=0;j<n;j++)cout<<c[i][j];
      cout<<endl;
    }
  }
  return 0;
}

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

using namespace std;

char field[101][101];

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

bool check(int x,int y,int angle){
	if(!(y>=0&&x>=0&&y<n&&x<n)){
		return false;
	}

	for(int i = 0; i < 4; i++){
		if(angle==i)
			continue;
		int nx=dx[i]+x;
		int ny=dy[i]+y;
		if(!(ny>=0&&nx>=0&&ny<n&&nx<n)){
			continue;
		}
		if(field[ny][nx]=='#'){
			return false;
		}
	}
	return true;
}

int main(){

	int nn;
	cin>>nn;
	for(int i = 0; i < nn; i++){
		if(i!=0)
			cout<<endl;
		cin>>n;
		memset(field,0,sizeof(field));

		if(n==1){
			cout<<" "<<endl;
			continue;
		}

		// 0:ツ右,1:ツ可コ,2:ツ債カ,3:ツ湘」
		int angle=3;
		int cx=0;
		int cy=n-1;
		int cnt=0;
		field[cy][cx]='#';
		while(1){
			if(angle==3){
				int ny=cy-1;
				int nx=cx;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=0;
				}
			}
			else if(angle==2){
				int ny=cy;
				int nx=cx-1;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=3;
				}
			}
			else if(angle==1){
				int ny=cy+1;
				int nx=cx;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=2;
				}
			}
			else if(angle==0){
				int ny=cy;
				int nx=cx+1;
				if(check(nx,ny,angle)){
					field[ny][nx]='#';
					cnt=0;
					cy=ny;
					cx=nx;
				}
				else{
					if(cnt>=1){
						break;
					}
					cnt++;
					angle=1;
				}
			}
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				cout<<field[i][j];
			}
			cout<<endl;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
char buf[150][150];
int dx[4]={-1,0,1,0};
int dy[4]={0,1,0,-1};
bool check(int tx,int ty)
{
    if(tx<0||ty<0)return false;
    return buf[tx][ty]=='#';
}
void solve(int x)
{
    memset(buf,' ',sizeof(buf));
    for(int i=1;i<=x;i++)
    {
        for(int j=1;j<=x;j++)
        {
            buf[i][j]='#';
        }
    }
    int X=x,Y=2;
    int cnt=0;
    for(int p=0;p<=10000;p++)
    {
        if(X>x+10||Y>x+10||X<0||Y<0)break;
        if(x%4==1&&X==(x+3)/2&&Y==(x+1)/2)break;
        if(x%4==3&&X==(x+1)/2&&Y==(x+3)/2)break;
        buf[X][Y]=' ';
        X+=dx[cnt];Y+=dy[cnt];
        if(check(X+dx[cnt],Y+dy[cnt])&&!check(X+dx[cnt]*2,Y+dy[cnt]*2))
        {
            cnt++;
            cnt%=4;
        }
    }
    for(int i=1;i<=x;i++)
    {
        for(int j=1;j<=x;j++)
        {
            cout << buf[i][j];
        }
        cout << endl;
    }
    return;
}
int main()
{
    int q;
    cin >> q;
    for(int i=0;i<q;i++)
    {
        int k;
        cin >> k;
        solve(k);
		if(i!=q-1)cout << endl;
    }
    return 0;
}

C++: #include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 10000000;
using namespace std;

int main()
{
	char b[100][100];
	int n, d, dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
	
	cin >> d;
	rep(t, d) {
		memset(b, ' ', sizeof(b));
		
		cin >> n;
		rep(i, n) b[0][i]='#';
		int x=0, y=0, nn = n, direct=0;
		
		while (1) {
			for (int i=0; i<nn; i++) {
				b[x][y] = '#';
				x+=dx[direct]; y+=dy[direct];
			}
			x-=dx[direct]; y-=dy[direct];
			direct++; direct%=4;
			
			if (n%2==0 && nn<=2) break;
			
			for (int i=0; i<nn; i++) {
				b[x][y] = '#';
				x+=dx[direct]; y+=dy[direct];
			}
			x-=dx[direct]; y-=dy[direct];
			direct++; direct%=4;
			nn-=2;
			
			if (nn<=1)
				break;
		}
		rep(y, n) {
			rep(x, n)
			cout << b[x][y];
			cout << endl;
		}

	}
	return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};

void solve(int n) {
	if (n == 1) {
		cout << '#' << endl;
		return;
	}
	char field[n][n + 1];
	memset(field, ' ', sizeof(field));
	for (int i = 0; i < n; i++) {
		field[i][n] = '\0';
	}
	int x = 0, y = n - 1, d = 0;
	while (true) {
		field[y][x] = '#';
		int newX = x + dx[d];
		int newY = y + dy[d];
		if (newX < 0 || n <= newX || newY < 0 || n <= newY
				|| field[newY+ dy[d]][newX+ dx[d]] == '#') {
			d = (d + 1) % 4;
			newX = x + dx[d];
			newY = y + dy[d];
		}
		int count = 0;
		for (int i = 0; i < 4; i++) {
			int cx = newX + dx[i];
			int cy = newY + dy[i];
			if (0 <= cx && cx < n && 0 <= cy && cy < n && field[cy][cx] == '#') count++;
		}
		if (count > 1) break;
		x = newX;
		y = newY;
	}
	for (int i = 0; i < n; i++) {
		cout << field[i] << endl;
	}
}

int main () {
	int d;
	cin >> d;
	for (int i = 0; i < d; i++) {
		int n;
		cin >> n;
		if (i != 0) cout << endl;
		solve(n);
	}
	return 0;
}