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>
using namespace std;

char map[255][255];

int dire4[][2] = {
    {1, 0}, {-1, 1}, {0, 1}, {1, 1}, 
    //{-1, -1}, {0, -1}, {1, -1}, {-1, 0}
};

int main(){
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;

        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                cin >> map[y][x];
            }
        }

        int ans = 0;
        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                for(int z = 0;z < 4;z++) {
                    int dx = dire4[z][0], dy = dire4[z][1];
                    int cx = x, cy = y, c = 0;
                    for(;map[cy][cx] == '1' && 0 <= cx && cx < n && 0 <= cy && cy < n;cx += dx, cy += dy, c++);
                    ans = max(ans, c);
                }
            }
        }
        cout << ans << endl;
    }
}

C++: #include <iostream>
#include <cmath>
#include <cstdlib>
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];
        
        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<bits/stdc++.h>
using namespace std;
int n, ans, G[300][300][4];
int mv[4][2] = { { -1,0 },{ 0,-1 },{ -1,-1 },{ -1,1 } };
signed main(void) {
	while (scanf("%d", &n) && n) {
		memset(G, 0, sizeof(G)), ans = 0; getchar();
		for (int i = 1; i <= n; i++, getchar())
			for (int j = 1; j <= n; j++) if (getchar()-'0')
				for (int k = 0; k < 4; k++)
					G[i][j][k] = G[i + mv[k][0]][j + mv[k][1]][k] + 1,
					ans = ans < G[i][j][k] ? G[i][j][k] : ans;
		printf("%d\n", ans);
	}
}

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

string s[1000];
int N, dx[] = {0, 1, 1, -1}, dy[] = {1, 0, 1, 1};

int search(int sx, int sy, int dx, int dy)
{
	int n = 0;
	int x = sx, y = sy;
	while(x >= 0 && x < N && y >= 0 && y < N && s[y][x] == '1')
	{
		n++;
		x += dx; y += dy;
	}
	return n;
}

int main() {
loop:
	cin >> N;
	if(!N)
	return 0;
	for(int i = 0; i < N; i++)
		cin >> s[i];
		
	int a = 0;
	for(int y = 0; y < N; y++)
	{
		for(int x = 0; x < N; x++)
		{
			for(int i = 0; i < 4; i++)
				a = max(a, search(x, y, dx[i], dy[i]));	
		}
	}
	cout << a << endl;
	goto loop;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 256;

int n,cnt;
int wx[]={1,-1},hy[]={1,-1};
int x1[]={1,-1},y1[]={1,-1};
int x2[]={1,-1},y2[]={-1,1};
int in[MAX_N][MAX_N];
int s[MAX_N][MAX_N];

void Wcheck(int x,int y){
    if(0 > x || n <= x) return;
    s[x][y] = 0;
    cnt++;
    
    for(int i = 0 ; i < 2 ; i++){
        int nx = x + wx[i];
        if(0 <= nx && nx < n && s[nx][y] == 1) Wcheck(nx,y);
    }
}

void Hcheck(int x,int y){
    if(0 > y || n <= y) return;
    s[x][y] = 0;
    cnt++;
    
    for(int i = 0 ; i < 2 ; i++){
        int ny = y + hy[i];
        if(0 <= ny && ny < n && s[x][ny] == 1) Hcheck(x,ny);
    }
}

void t1(int x,int y){
    if(0 > x || n <= x || 0 > y || n <= y) return;
    s[x][y] = 0;
    cnt++;
    
    for(int i = 0 ; i < 2 ; i++){
        int nx = x + x1[i];
        int ny = y + y1[i];
        
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[nx][ny] == 1){
            t1(nx,ny);
        }
    }
}

void t2(int x,int y){
    if(0 > x || n <= x || 0 > y || n <= y) return;
    s[x][y] = 0;
    cnt++;
    
    for(int i = 0 ; i < 2 ; i++){
        int nx = x + x2[i];
        int ny = y + y2[i];
        
        if(0 <= nx && nx < n && 0 <= ny && ny < n && s[nx][ny] == 1){
            t2(nx,ny);
        }
    }
}
void cp_str(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}

int main(){
    while(cin >> n ,n){
        int a = 0,b = 0,c = 0,d = 0;
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cin >> in[i][j];
            }
        }
        
        cp_str();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) Wcheck(i,j);
                a = max(a,cnt);
            }
        }
        
        cp_str();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) Hcheck(i,j);
                b = max(b,cnt);
            }
        }

        cp_str();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) t1(i,j);
                c = max(c,cnt);
            }
        }
        
        cp_str();
        for(int i = 0 ; i < n ; i++){
            for(int j = 0 ; j < n ; j++){
                cnt = 0;
                if(s[i][j] == 1) t2(i,j);
                d = max(d,cnt);
            }
        }
        
        cout << max(max(a,b),max(b,d)) << endl;
    }
    
    return 0;
}