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;

char map[104][104];

void next(int x,int y,int r){
	int sum=0;
	int nx[4]={0,1,0,-1};
	int ny[4]={-1,0,1,0};
	for(int i=0;i<4;i++)if(map[x+nx[i]][y+ny[i]]=='#')sum++;
	if(sum<=1){
		map[x][y]='#';
		if(map[x+nx[r]*2][y+ny[r]*2]=='#'){
			r=(r+1)%4;
			next(x+nx[r],y+ny[r],r);
		}
		else{
			next(x+nx[r],y+ny[r],r);
		}
	}
}

void cal(int n){
	for(int i=0;i<104;i++)for(int j=0;j<104;j++)map[i][j]=' ';
	for(int i=0;i<104;i++)map[i][0]=map[0][i]=map[i][n+3]=map[n+3][i]='#';
	next(2,n+1,0);
}

void draw(int n){
	for(int i=2;i<=n+1;i++){
		for(int j=2;j<=n+1;j++){
			cout<<map[j][i];
		}
		cout<<endl;
	}
}
int main(){
	int d,n;
	cin>>d;
	for(int i=1;i<=d;i++){
		cin>>n;
		cal(n);
		draw(n);
		if(i!=d)cout<<endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
char t[100][100];
int n,a,x,y,d,ny,nx,flg,cnt;
int dx[4]={0,1,0,-1};
int dy[4]={-1,0,1,0};
int main(){
  cin>>n;
  while(n--){
    cin>>a;

    for(int i=0;i<100;i++)
      for(int j=0;j<100;j++)
	t[i][j]=' ';
    
    t[a-1][0]='#';
    x=0;y=a-1;
    cnt=100;
    flg=1;
    while(flg){

      flg=0;

      for(d=0;d<4;d++){
	if(cnt<=1)break;
	cnt=0;
	while(1){


	    ny=y+(dy[d]*2);
	    nx=x+(dx[d]*2);
	    
	    if(ny>=0&&ny<a&&nx>=0&&nx<a){
	      if(t[ny][nx]=='#'){

		break;
	      }
	    }
	  

	  ny=y+dy[d];
	  nx=x+dx[d];
	  if(ny>=0&&ny<a&&nx>=0&&nx<a){
	    if(t[ny][nx]=='#')break;
	  }
	  
	  
	 
	  x+=dx[d];
	  y+=dy[d];
	  
	  if(x<0||y<0||x>=a||y>=a){
	    x-=dx[d];y-=dy[d];
	    break;
	  }
	   t[y][x]='#';
	   flg=1;cnt++;
	  
	  
	}//for d
      }
    }//while
    

    for(int i=0;i<a;i++){
      for(int j=0;j<a;j++){
	cout<<t[i][j];
      }
      cout<<endl;
    }
    if(n>1)cout<<endl;
  }
  return 0;
}

C++: ar MAP[104][104];
int nx,ny,vx=0,vy=-1;
void rotate(){ //EñèÉñ]·é
	int tx=vx,ty=vy;
	vx=-ty;vy=tx;
}
int main(){
	int s; //}bvÌL³
	int n; //·éÂ
	int t; //I¹»èp
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s);
		memset(MAP,'#',104*104);
		for(int x=1;x<1+s+2;x++){
			for(int y=1;y<1+s+2;y++){
				MAP[x][y]=' ';
			}
		}
		nx=2,ny=s+1;t=0;vx=0;vy=-1;
		while(1){
			MAP[nx][ny]='#';
			if(MAP[nx+vx*2][ny+vy*2]=='#'){
				if(t>0) break;
				t=2;
				rotate();
			} else {
				t--;
				nx+=vx;ny+=vy;
			}
		}
		//\¦
		if(i!=0) puts("");
		for(int y=2;y<1+s+1;y++){
			for(int x=2;x<1+s+1;x++){
				printf("%c",MAP[x][y]);
			}
			puts("");
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
 
#define MAX 150
 
char sp[MAX][MAX];
//u r d l
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
 
bool range(int x, int y, int n)
{
    if (0 > x || x >= n || 0 > y || y >= n) {
	return 0;
    }
    return 1;
}
 
void make(int n)
{
    int x = 0, y = n-1, dir = 0;
 
    for (int i = 0; i < n; i++) {
	for (int j = 0; j < n; j++) {
	    sp[i][j] = '.';
	}
    }
    int end = 0;
    sp[y][x] = '#';
    while (1) {
	int nx = x + dx[dir];
	int ny = y + dy[dir];  
 
	bool flg = 1;
	if (!range(nx, ny, n)) {
	    flg = 0;
	}
 
	for (int i = 0; i < 4; i++) {
	    int nnx = nx + dx[i];
	    int nny = ny + dy[i];
 
	    if ((x == nnx && y == nny) 
	       || !range(nnx, nny, n)) {
		continue;
	    }
 
	    if (sp[nny][nnx] == '#') {
		flg = 0;
		break;
	    }
	}
 
	if (!flg) {
	    dir++;
	    dir = dir % 4;
	    end++;
	    if (end == 4) return;
	} else {
	    end = 0;
	}
 
	if (flg) {
	    sp[ny][nx] = '#';
	    x = nx;
	    y = ny;
	}
    }
}
 
int main()
{
    int d, n;
    bool ok = 0;
 
    scanf("%d", &d);
    while (d--) {
	scanf("%d", &n);
 
	if (ok) {
	    puts("");
	}
	ok = 1;
	make(n);
	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < n; j++) {
		if (sp[i][j] == '.') {
		    printf(" ");
		} else {
		    printf("%c", sp[i][j]);
		}
	    }
	    puts("");
	}   
    }
    return 0;
}

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

using namespace std;

main(){
  int n;
  char data[100][100];
  int dx[] = {0, 1, 0, -1};
  int dy[] = {-1, 0, 1, 0};
  int t;
  while(cin >> t){
    for(int tc=0;tc<t;tc++){
      cin >> n;
      if(n<0 || n>100) while(1);
      if(tc != 0) cout << endl;
      if(n == 1){
	cout << "#" << endl;
	continue;
      }
      int y = n-1;
      int x = 0;
      fill(data[0], data[100], ' ');
      data[y][x] = '#';
      int d = 0;
      while(1){
	int ty = y + dy[d];
	int tx = x + dx[d];
	if(ty<0 || ty>=n){ d = (d+1)%4; continue; }
	if(tx<0 || tx>=n){ d = (d+1)%4; continue; }
	if(data[ty][tx] == '#') break;
	int tty = ty + dy[d];
	int ttx = tx + dx[d];
	if((tty>=0 || tty<n) && (ttx>=0 || ttx<n)){
	  if(data[tty][ttx] == '#'){
	    d = (d+1)%4; 
	    continue; 
	  }
	}
	int cnt = 0;
	for(int i=0;i<4;i++){
	  int tty = ty + dy[i];
	  int ttx = tx + dx[i];
	  if(tty<0 || tty>=n) continue;
	  if(ttx<0 || ttx>=n) continue;
	  if(data[tty][ttx] == '#') cnt++;
	}
	if(cnt > 1) break;
	data[ty][tx] = '#';
	y = ty;
	x = tx;
      }
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  cout << data[i][j];
	}
	cout << endl;
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int main(){
	int d,n;
	cin>>d;
	REP(times,d){
		cin>>n;
		char fld[n][n],a,b;
		REP(i,(n+1)/2){
			if(i%2==0){a='#';b=' ';}
			else{a=' ';b='#';}
			REP(j,(n-i*2)){
				fld[i+j][i]=a;
				fld[i][i+j]=a;
				fld[n-1-i][i+j]=a;
				fld[i+j][n-1-i]=a;
			}
			fld[i+1][n-1-i]=b;
		}
		if(n%4==0)fld[n/2][n/2]=' ';
		REP(i,n){
			REP(j,n)cout<<fld[j][i];
			cout<<endl;
		}
		if(times!=d-1)cout<<endl;
	}
}