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<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y;
	int dx[]={1,1,0,-1},dy[]={0,-1,-1,-1};
	char xy[225][226];
	while(1){
		max=0;
		cin>>n;
		if(n==0) break;
		for(i=0;i<n;i++) cin>>xy[i];
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(xy[i][j]=='1'){
					for(k=0;k<4;k++){
						cnt=1;
						y=i; x=j;
						while(1){
							y=y+dy[k]; x=x+dx[k];
							if(y>=n||x>=n||y<0||x<0) break;
							if(xy[y][x]!='1')break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

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

using namespace std;

const int MAX_N = 255;
int n;
char grid[MAX_N][MAX_N];
int dp[MAX_N][MAX_N][4];

int main()
{
    while(cin >> n && n) {
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                cin >> grid[i][j];
        
        memset(dp, 0, sizeof(dp));
        for(int j = 0; j < n; j++) 
            for(int k = 0; k < 4; k++) 
                dp[0][j][k] = grid[0][j] - '0';

        int ans = 0;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                if(grid[i][j] == '0') {
                    for(int k = 0; k < 4; k++)
                        dp[i][j][k] = 0;
                } else {
                    dp[i][j][0] = (j) ? dp[i-1][j-1][0] + 1 : 1;
                    dp[i][j][1] = dp[i-1][j][1] + 1;
                    dp[i][j][2] = (j != n - 1) ? dp[i-1][j+1][2] + 1 : 1;
                    dp[i][j][3] = (j) ? dp[i][j-1][3] + 1 : 1;
                }
                for(int k = 0; k < 4; k++)
                    ans = max(ans, dp[i][j][k]);
            }
        }

        cout << ans << endl;
    }
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,j,c,max_c;
	while(scanf("%d",&n),n)
	{
		const int OFFSET = 256,MAX_I=OFFSET,MAX_J=OFFSET*3;
		char a[MAX_I][MAX_J] = {0};
		for(i=0;i<n;++i)
			scanf("%s",&a[i][OFFSET]);
		max_c = c =0;
		for(j=OFFSET;j<MAX_J;++j)
			for(c=0,i=OFFSET;i<MAX_I;++i)
				(a[i][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(i=OFFSET;i<MAX_I;++i)
			for(c=0,j=OFFSET;j<MAX_I;++j)
				(a[i][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(i=0; i<MAX_I; ++i)
			for(c=0,j=0; j<MAX_J && i+j<=MAX_I; ++j)
				(a[i+j][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(j=0; j<MAX_J; ++j)
			for(c=0,i=0;i<MAX_I; ++i)
			{
				if( j-i>=0)
					(a[i][j-i]=='1') ? max_c=max(++c,max_c): c=0;
			}
		printf("%d\n",max_c);
	}
	return 0;
}

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

using namespace std;

int grid[256][256];
int hor[256][256],ver[256][256],ske1[256][256],ske2[256][256];

int main()
{
	for(int n;scanf("%d ",&n),n;){
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++)	grid[i][j]=getchar()-'0';
			getchar();
		}

		for(int i=0;i<n;i++){
			hor[i][0]=grid[i][0];
			ver[0][i]=grid[0][i];
			ske1[0][i]=ske2[0][i]=grid[0][i];
			ske1[i][0]=grid[i][0];
			ske2[i][n-1]=grid[i][n-1];
		}

		for(int i=0;i<n;i++){
			for(int j=1;j<n;j++){
				hor[i][j]=grid[i][j]?hor[i][j-1]+1:0;
				ver[j][i]=grid[j][i]?ver[j-1][i]+1:0;
			}
		}

		for(int i=1;i<n;i++){
			for(int j=1;j<n;j++){
				ske1[i][  j  ]=grid[i][  j  ]?ske1[i-1][j-1]+1:0;
				ske2[i][n-j-1]=grid[i][n-j-1]?ske2[i-1][n-j]+1:0;
			}
		}

		int lmax=0;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)
			lmax=max(lmax,max(max(hor[i][j],ver[i][j]),max(ske1[i][j],ske2[i][j])));
		printf("%d\n",lmax);
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;

int n;

const int MAX = 255;
int M[MAX][MAX];

int solve()
{
	int mval = 0;
	
	for(int i=0; i<n; i++)
	{
		int c = 0;
		for(int j=0; j<n; j++)
		{
			if(M[i][j]==1)
			{
				c++;
			}
			else
			{
				if(c > mval) mval =c;
				c = 0;
			}
		}
		
		if(c > mval)
		{
			mval = c;
		}
	}
	
	for(int i=0; i<n; i++)
	{
		int c = 0;
		for(int j=0; j<n; j++)
		{
			if(M[j][i]==1)
			{
				c++;
			}
			else
			{
				if(c > mval) mval =c;
				c = 0;
			}
		}
		
		if(c > mval)
		{
			mval = c;
		}
	}
	
	for(int i=0; i<n; i++)
	{
		int c = 0;
		for(int j=0; j<=i; j++)
		{
			if(M[i-j][j]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		c = 0;
		for(int j=0; j<n-i; j++)
		{
			if(M[i+j][j]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		c = 0;
		for(int j=0; j<=i; j++)
		{
			if(M[i-j][n-j-1]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		c = 0;
		for(int j=0; j<n-i; j++)
		{
			if(M[i+j][n-j-1]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		
	}
	
	return mval;
}

int main(int argc, char** argv)
{
	string tmp;
	char c[1];
	
	while(cin >> n, n)
	{
		for(int i=0; i<n; i++)
		{
			cin >> tmp;
			for(int j=0; j<n; j++)
			{
				memcpy(c, &tmp[j], sizeof(char));
				M[i][j] = atoi(c);
			}
		}
		
		cout << solve() << endl;;
	}
}

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

#define SIZE 257

int table[256][256];

enum {
	RIGHT_DOWN = 0,
	DOWN,
	LEFT_DOWN
};

int current_counts[SIZE][3]; //1ツ篠淞：ツ暗環置ツ、2ツ篠淞：ツ古シツつォ
int next_counts[SIZE][3];
int max_count = 0;

void init_counts() {
	for (int i = 0; i < SIZE; ++i) {
		for (int j = 0; j < 3; ++j) {
			current_counts[i][j] = next_counts[i][j] = 0;
		}
	}
}

void check_max(int expect) {
	if(expect > max_count) {
		max_count = expect;
	}
}

int main() {
	while (true) {
		int n;
		cin >> n;
		if(n == 0) {
			break;
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				char o;

				cin >> o;
				table[i][j] = o - '0';
			}
		}

		init_counts();
		max_count = 0;
		int cont_vertical = 0;

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if(table[i][j] == 1) {
					cont_vertical++;

					next_counts[j][DOWN] = current_counts[j][DOWN] + 1;
					if(j+1 < n) {
						next_counts[j+1][RIGHT_DOWN] = current_counts[j][RIGHT_DOWN] + 1;
					}
					else {
						check_max(current_counts[j][RIGHT_DOWN] + 1);
					}
					if(j > 0) {
						next_counts[j-1][LEFT_DOWN] = current_counts[j][LEFT_DOWN] + 1;
					}
					else {
						check_max(current_counts[j][LEFT_DOWN] + 1);
					}
				}
				else {
					check_max(cont_vertical);
					cont_vertical = 0;
					for (int k = 0; k < 3; ++k) {
						check_max(current_counts[j][k]);
					}
				}
				for (int k = 0; k < 3; ++k) {
				}
			}
			for (int j = 0; j < n; ++j) {
				for (int k = 0; k < 3; ++k) {
					current_counts[j][k] = next_counts[j][k];
					next_counts[j][k] = 0;
				}
			}
		}
		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < 3; ++j) {
				check_max(current_counts[i][j]);
			}
		}

		cout << max_count << endl;
	}
	return 0;
}