Go: package main

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

var scanner= bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		mp := make([]string, n)
		for i := range mp {
			scanner.Scan()
			mp[i] = "0" + scanner.Text() + "0"
		}
		tmp := make([]string, n+2)
		for i := range tmp {
			tmp[i] = "0"
		}
		mp = append([]string{strings.Join(tmp, "")}, mp...)
		mp = append(mp, strings.Join(tmp, ""))
		score := make([][][]int, n+2)
		for i := range score {
			score[i] = make([][]int, n+2)
			for j := range score[i] {
				score[i][j] = make([]int, 4)
			}
		}
		max_score := 0
		for i := 1; i < n+1; i++ {
			for j := 1; j < n+1; j++ {
				tmps := mp[i]
				if string(tmps[j]) == "1" {
					score[i][j][0] = score[i - 1][j][0] + 1
					score[i][j][1] = score[i][j - 1][1] + 1
					score[i][j][2] = score[i - 1][j - 1][2] + 1
					score[i][j][3] = score[i - 1][j + 1][3] + 1
					max_score = max(max_score, score[i][j][0], score[i][j][1], score[i][j][2], score[i][j][3])
				}
			}
		}
		fmt.Println(max_score)
	}
}

func max(a, b, c, d, e int) int {
	buf := []int{a, b, c, d, e}
	sort.Ints(buf)
	return buf[len(buf)-1]
}

C++: #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
using namespace std;
typedef vector<int> vi;
string board[265];

int main()
{
  int n;
  while(cin >> n && n)
    {
      int ans=-1;
      int wchain=0;
      int hchain=0;
      int schain=0;
      for(int i=0;i<n;i++)
	{
	  cin >> board[i];
	}
      for(int i=0;i<n;i++)
	{
	  wchain=0;
	  for(int j=0;j<n;j++)
	    {
	      if(board[i][j]=='1')
		{
		  wchain++;
		}
	      else
		{
		  ans=max(ans,wchain);
		  wchain=0;
		}
	    }
	  ans=max(ans,wchain);
	}
      for(int i=0;i<n;i++)
	{
	  hchain=0;
	  for(int j=0;j<n;j++)
	    {
	      if(board[j][i]=='1')
		{
		  hchain++;
		}
	      else
		{
		  ans=max(ans,hchain);
		  hchain=0;
		}
	    }
	   ans=max(ans,hchain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=i,w=0;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h-1)>=0 && (w+1)<n)
	    {
	      h--;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	   ans=max(ans,schain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=n-1,w=i;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h-1)>=0 && (w+1)<n)
	    {
	      h--;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}


       for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=i,w=0;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h+1)<n && (w+1)<n)
	    {
	      h++;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=0,w=i;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h+1)<n && (w+1)<n)
	    {
	      h++;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}
      cout << ans << endl;
    }
  return 0;
}

C++: #include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int main(){
  int fld[255][255][5];
  int n;
  string in;
  while(cin>>n&&n){
    for(int i=0;i<255;i++)for(int j=0;j<255;j++)for(int k=0;k<5;k++)fld[i][j][k]=0;
    for(int i=0;i<n;i++){
      cin>>in;
      for(int j=0;j<n;j++){
        fld[i][j][0]=in[j]-'0';
      }
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(fld[i][j][0]==0){
          for(int k=1;k<5;k++)fld[i][j][k]=0;
          continue;
        }else for(int k=1;k<5;k++)fld[i][j][k]=1;
        if(i!=0){
          fld[i][j][1]=fld[i-1][j][1]+1;
          if(j!=0){
            fld[i][j][2]=fld[i-1][j-1][2]+1;
          }
          if(j!=n-1){
            fld[i][j][3]=fld[i-1][j+1][3]+1;
          }
        }
        if(j!=0){
          fld[i][j][4]=fld[i][j-1][4]+1;
        }
      }
    }
    int ans=0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        for(int k=1;k<5;k++){
          ans=max(ans,fld[i][j][k]);
        }
      }
    }
    cout<<ans<<endl;
  }
}

C++: /*
  AOJ 0151
  Title:Grid
  @kankichi573
*/
#include <stdio.h>
int max(int x,int y) 
{
return  (((x)>(y))?(x):(y));
}
int n;
char grid[255][256];
int max_ren(int sx,int sy,int xoffs,int yoffs,int limit)
{
  int i,j,ren=0,max_=0;

  for(i=sx,j=sy;i<limit && i>=0 && j<limit && j >= 0 ;i+=xoffs,j+=yoffs)
    {
    if(grid[i][j]=='1')
      {
	ren++;
	if(ren>max_)
	  max_=ren;
      }
    else
      ren=0;
    }
  return(max_);
}
int solve()
{
  int i,ret;

  ret=0;
  for(i=0;i<n;i++)
    {
      ret=max(ret,max_ren(0,i,1,0,n));
      ret=max(ret,max_ren(0,i,1,1,n));
      ret=max(ret,max_ren(0,i,1,-1,n));
    }
  for(i=0;i<n;i++)
    {
      ret=max(ret,max_ren(i,0,0,1,n));
      ret=max(ret,max_ren(i,0,1,1,n));
    }
  return(ret);
}
main()
{
  int  i;

  while(scanf("%d",&n) && n)
    {
      for(i=0;i<n;i++)
	scanf("%s",&grid[i][0]);
      printf("%d\n",solve());
    }
  return(0);
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{ 
	int n;
	while( cin >> n && n )
	{
		vector < string > map(n);
		for ( int i = 0; i < n; i++ )
			cin >> map[i];

		int answer = 0;
		int cnt;

		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				if ( map[i][j] == '0' )
					continue;

				cnt = 0;
				while ( i+cnt < n )
				{
					if ( map[i+cnt][j] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );

				cnt = 0;
				while ( j+cnt < n )
				{
					if ( map[i][j+cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );

				cnt = 0;
				while ( i+cnt < n && j+cnt < n )
				{
					if ( map[i+cnt][j+cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );

				cnt = 0;
				while ( i+cnt < n && j-cnt >= 0 )
				{
					if ( map[i+cnt][j-cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );
			}
		}

		cout << answer << endl;

	}
	return 0;
}

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

char s[257][257];
int n;

int check(int i, int j)
{
	int ii, jj;
	int count;
	count = 0;
	for (ii = 1; ii < n-i; ii++) if (s[i+ii][j]=='0') break;
	if (ii>count) count = ii;
	for (jj = 1; jj < n-j; jj++) if (s[i][j+jj]=='0') break;
	if (jj>count) count = jj;
	for (ii = 1, jj = 1; ii < n-i && jj < n-j; ii++, jj++) if (s[i+ii][j+jj]=='0') break;
	if (ii>count) count = ii;
	for (ii = 1, jj = 1; ii <= i && jj < n-j; ii++, jj++) if (s[i-ii][j+jj]=='0') break;
	if (ii>count) count = ii;
	return count;
}

int main()
{
	int i, j;
	int max, t;
	while (scanf("%d",&n)!=EOF, n) {
		for (i = 0; i < n; i++) scanf("%s",s[i]);
		max = 0;
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++) {
				if (s[i][j]=='1') {
					t = check(i, j);
					if (max < t) max = t;
				}
			}
		printf("%d\n",max);
	}
	return 0;
}