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;

bool field[100][100];

void migi(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x+i] = 1;
	}
}
void sita(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y+i][x] = 1;
	}
}
void hidari(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x-i] = 1;
	}
}
void ue(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y-i][x] = 1;
	}
}	
int main()
{
	int a;
	cin >> a;
	for(int i=0;i<a;i++){
		int n;
		cin >> n;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				field[j][k] = 0;
			}
		}
		int y=n-1,x=0;
		for(int j=0;j<n;j++){
			field[y-j][x] = 1;
		}
		y = 0;
		
		for(int j=n-1;j>=0;j-=2){
			migi(y,x,j);
			x = x+j;
			sita(y,x,j);
			y = y+j;			
			j-=2;
			hidari(y,x,j);
			x = x-j;
			ue(y,x,j);
			y = y-j;
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(field[i][j] == 1)
					cout << '#';
				else
					cout << ' ';
			}
			cout << endl;
		}
	}
	return 0;
}

C++: // AOJ 0141
#include<iostream>
#include<cstring>

char ptn[104][105];
const int dx[4] = { 0, 1, 0, -1 }, dy[4] = { -1, 0, 1, 0 };
int dir;

bool check( int x, int y, int dir )
{
	int nx = x + dx[dir], ny = y + dy[dir];

	for( int i = 0; i != 4; ++i )
	{
		int nnx = nx + dx[i], nny = ny + dy[i];

		if( nnx == x && nny == y )
			continue;

		if( ptn[nny][nnx] == '#' )
			return false;
	}

	return true;
}

int main()
{
	int d;
	std::cin >> d;
	while( d-- )
	{
		int n;
		std::cin >> n;

		for( int i = 0; i != n + 4; ++i )
			for( int j = 0; j != n + 4; ++j )
				ptn[i][j] = !i || !j || i == n + 3 || j == n + 3 ? '#' : ' ';

		int x = 2, y = n + 1;
		bool fl = false;
		dir = 0;

		while( true )
		{
			ptn[y][x] = '#';

			if( !check( x, y, dir ) )
			{
				if( !fl )
				{
					dir = ( dir + 1 ) & 3;
					fl = true;
					continue;
				}
				else
					break;
			}
			else
				fl = false;

			x += dx[dir];
			y += dy[dir];
		}

		for( int i = 2; i != n + 2; ++i )
		{
			for( int j = 2; j != n + 2; ++j )
				std::cout << ptn[i][j];

			std::cout << std::endl;
		}

		if( d )
			std::cout << std::endl;
	}

	return 0;
}

C++: #include<cstdio>

using namespace std;

int main()
{
	char sp[103][103];
	bool chk[103][103];
	int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
	int t;	scanf("%d",&t);

	for(int k=0;k<t;k++){
		if(k>0)	puts("");

		int n;	scanf("%d",&n);
		for(int i=0;i<=n+1;i++)	for(int j=0;j<=n+1;j++)	chk[i][j]=true;
		for(int i=1;i<=n;i++)	for(int j=1;j<=n;j++)	sp[i][j]=' ',chk[i][j]=false;

		int x=1,y=n,di=1;
		sp[y][x]='#';
		while(1){
			if(chk[y+dy[di]][x+dx[di]]){
				di=(di+3)%4;
				if(chk[y+dy[di]][x+dx[di]])	break;
			}
			else{
				int xl,yl,xr,yr;
				xl=x+dx[(di+1)%4];	yl=y+dy[(di+1)%4];
				xr=x+dx[(di+3)%4];	yr=y+dy[(di+3)%4];
				chk[yl][xl]=chk[yr][xr]=true;

				x+=dx[di];	y+=dy[di];
				sp[y][x]='#';
			}
		}

		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)	putchar(sp[i][j]);
			puts("");
		}
	}

	return 0;
}

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

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

void func(){
	char table[110][110] ;
	
	for( int i=0 ; i<102 ; i++ ){
		for( int j=0 ; j<102 ; j++ ){
			if( i>=100-N+1 && 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+1 ; i<=100 ; i++ ){
		for( int j=1 ; j<=N ; j++ ){
			cout << table[i][j] ;
		}
		if( d || i<100 ) cout << endl ;
	}
}

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

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <set>
#include <cstring>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n) 
int nx,ny,nr;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int a[100][100];
bool plot(int x, int y, int r, int n){
  int count = 0;
  bool flag = true;
  if((x+2*dx[r]>=0&&x+2*dx[r]<n)&&
      y+2*dy[r]>=0&&y+2*dy[r]<n&&a[x+2*dx[r]][y+2*dy[r]]==1)
    return false;
  x+=dx[r]; y+=dy[r];
  while((x>=0&&x<n)&&(y>=0&&y<n)){
    if((x+2*dx[r]>=0&&x+2*dx[r]<n)&&y+2*dy[r]>=0&&y+2*dy[r]<n&&a[x+2*dx[r]][y+2*dy[r]]==1) flag = false;
    a[x][y] = 1;
    x+=dx[r]; y+=dy[r];
    count++;
    if(!flag) break;
  }
  x-=dx[r];y-=dy[r]; nx=x; ny=y; nr=(r+1)%4;
  if(count<2) return false;
  return true;
}
int main(void){
  int d;
  cin>>d;
  while(d--){
    int n;
    cin>>n;
    memset(a,0,sizeof(a));
    a[0][n-1]=1;
    nx=0; ny=n-1; nr=3;
    while(plot(nx,ny,nr,n));
    if(n==2) a[1][0]=1;
    REP(i,n){
      REP(j,n)
        printf("%c",(a[j][i]==1)?'#':' ');
      cout << endl;
    }
    if(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};

void rec(int y,int x,int d){

  /*

    for(int i=0;i<a;i++){
      for(int j=0;j<a;j++){
	cout<<t[i][j];
      }
      cout<<endl;
    }

    cout<<y<<' '<<x<<' '<<d<<endl;*/
  cnt=0;
  for(int i=0;i<a;i++){
    t[y][x]='#';cnt++;
    ny=y+dy[d]*2;
    nx=x+dx[d]*2;
    if(t[ny][nx]=='#'){
      break;
    }
    y=y+dy[d];
    x=x+dx[d];
  }
  if(cnt>=3)rec(y,x,(d+1)%4);
}

int main(){
  cin>>n;
  while(n--){
    cin>>a;
    if(a==1){
      cout<<'#'<<endl;
      continue;
    }if(a==2){
      cout<<"##"<<endl;
      cout<<"# "<<endl;
      continue;
    }

    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;
    
    for(int i=0;i<a;i++){
      t[a-1][i]=t[i][a-1]='#';
      t[0][i]=t[i][0]='#';
    }
    t[a-1][1]=' ';
    
    rec(a-1,2,0);
    



    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;
}