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 <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++ )
		{
			cnt = 0;
			for ( int j = 0; j < n; j++ )
			{
				if ( map[j][i] == '1' )
					cnt++;
			}
			answer = max( answer, cnt );

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

		for ( int i = 0; i < n; i++ )
		{
			for ( int j = 0; j < n; j++ )
			{
				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 >= 0 && j-cnt < n )
				{
					if ( map[i+cnt][j-cnt] == '0' )
						break;
					cnt++;
				}
				answer = max( cnt, answer );
			}
		}

		cout << answer << endl;

	}
	return 0;
}

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

int grid[255][255];

int main() {
    int n;
    while (cin >> n, n) {
        char c;
        for (int i=0; i<n; ++i) {
            for (int j=0; j<n; ++j) {
                cin >> c;
                grid[i][j] = c - '0';
            }
        }
        int x, y, cnt, res = 0;
        for (int i=0; i<n; ++i) {
            // right
            cnt = 0, y = i, x = 0;
            while (x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ x;
            }
            // down
            cnt = 0, y = 0, x = i;
            while (y < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y;
            }
            // right down
            cnt = 0, y = i, x = 0;
            while (y < n && x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, ++ x;
            }
            cnt = 0, y = 0, x = i;
            while (y < n && x < n) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, ++ x;
            }
            // left down
            cnt = 0, y = i, x = 0;
            while (y < n && 0 <= x) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, -- x;
            }
            cnt = 0, y = 0, x = i;
            while (y < n && 0 <= x) {
                cnt = (grid[y][x] ? cnt+1 : 0);
                res = max(res, cnt);
                ++ y, -- x;
            }
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <string>
#include <iostream>
#include <algorithm>
using namespace std;
int n; string a[255];
int check(int x, int y, int dx, int dy) {
	int ret = 0;
	while(0 <= x && x < n && 0 <= y && y < n) {
		if(a[y][x] == '0') return ret;
		x += dx, y += dy, ret++;
	}
	return ret;
}
int main() {
	while(~scanf("%d", &n), n) {
		for(int i = 0; i < n; i++) cin >> a[i];
		int ret = 0;
		for(int i = 0; i < n * n; i++) {
			for(int j = 0; j < 4; j++) {
				ret = max(ret, check(i / n, i % n, j / 3 - 1, j % 3 - 1));
			}
		}
		printf("%d\n", ret);
	}
}

C++: // 2012/11/19 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		char G[257][257];
		for(int y=1; y<=n; y++){
			for(int x=1; x<=n; x++){
				cin >> G[y][x];
			}
		}

		int dp[4][257][257];
		for(int i=0; i<4; i++){
			for(int y=0; y<=n+1; y++){
				for(int x=0; x<=n+1; x++){
					dp[i][y][x] = 0;
				}
			}
		}

		int dp_max = 0;

		for(int y=1; y<=n; y++){
			for(int x=1; x<=n; x++){
				if(G[y][x]=='1'){
					dp[0][y][x] = dp[0][y-1][x]+1;
					dp[1][y][x] = dp[1][y][x-1]+1;
					dp[2][y][x] = dp[2][y-1][x-1]+1;
					dp[3][y][x] = dp[3][y-1][x+1]+1;

					for(int i=0; i<4; i++){
						if(dp[i][y][x]>dp_max){
							dp_max = dp[i][y][x];
						}
					}
				}
			}
		}

		cout << dp_max << endl;
	}

	return 0;
}

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

int check(vector<string> s, int i, int j, int n)
{
	if (s[i][j]=='0') return 0;
	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 n, i, j;
	int max, t;
	vector<string> s;
	while (cin>>n, n) {
		s.clear();
		s.resize(n);
		for (i = 0; i < n; i++) cin>>s[i];
		max = 0;
		for (i = 0; i < n; i++)
			for (j = 0; j < n; j++) {
				t = check(s, i, j, n);
				if (max < t) max = t;
			}
		cout<<max<<endl;
	}
	return 0;
}

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

#define MAX 256

char s[MAX][MAX];
int n;

int findMax(int i, int j, int di, int dj){
	int count = 0, res = 0;

	while(0<=i && 0<=j && i<n && j<n){
		if(s[i][j] == '1') count++;
		else{
			res = max(res, count);
			count = 0;
		}
		i += di;
		j += dj;
	}

	return max(res, count);
}

int main(void){
	while(cin>>n && n){
		for(int i=0;i<n;i++) cin>>s[i];

		int ans = -1;
		for(int i=0;i<n;i++){
			ans = max(ans, findMax(i,0,0,1));
			ans = max(ans, findMax(0,i,1,0));
			ans = max(ans, findMax(i,0,1,1));
			ans = max(ans, findMax(0,i,1,1));
			ans = max(ans, findMax(i,n-1,1,-1));
			ans = max(ans, findMax(0,i,1,-1));
		}

		cout<<ans<<endl;
	}

	return 0;
}