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>
using namespace std;
int main(){
long n,i,j;
string s[256],t[512];
string::size_type p,q,m,l;
while(cin>>n){
if(n==0)break;
for(i=0;i<n;i++)cin>>s[i];
m=0;
for(i=0;i<n;i++){
q=-1;
for(;;){
p=s[i].find('1',q+1);if(p==string::npos)break;
q=s[i].find('0',p+1);if(q==string::npos){if(m<n-p)m=n-p;break;}
if(m<q-p)m=q-p;
}
}
for(i=0;i<n;i++){
t[i]="";
for(j=0;j<n;j++)t[i]+=s[j][i];
}
for(i=0;i<n;i++){
q=-1;
for(;;){
p=t[i].find('1',q+1);if(p==string::npos)break;
q=t[i].find('0',p+1);if(q==string::npos){if(m<n-p)m=n-p;break;}
if(m<q-p)m=q-p;
}
}
for(i=0;i<n*2-1;i++){
t[i]="";
for(j=0;j<n;j++){if(i-j>=0&&i-j<n)t[i]+=s[i-j][j];}
}
for(i=0;i<n*2-1;i++){
q=-1;l=t[i].size();
for(;;){
p=t[i].find('1',q+1);if(p==string::npos)break;
q=t[i].find('0',p+1);if(q==string::npos){if(m<l-p)m=l-p;break;}
if(m<q-p)m=q-p;
}
}
for(i=0;i<n*2-1;i++){
t[i]="";
for(j=0;j<n;j++){if(n-i+j>=0&&n-i+j<n)t[i]+=s[n-i+j][j];}
}
for(i=0;i<n*2-1;i++){
q=-1;l=t[i].size();
for(;;){
p=t[i].find('1',q+1);if(p==string::npos)break;
q=t[i].find('0',p+1);if(q==string::npos){if(m<l-p)m=l-p;break;}
if(m<q-p)m=q-p;
}
}
cout<<m<<endl;
}
return 0;
}

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

char map[255][255];

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++) {
                int dire4[][2] = {
                    {1, 0}, {-1, 1}, {0, 1}, {1, 1}, 
                    {-1, -1}, {0, -1}, {1, -1}, {-1, 0}
                };
                for(int z = 0;z < 8;z++) {
                    int dx = dire4[z][0], dy = dire4[z][1];
                    int cx = x, cy = y;
                    int c = 0;
                    for(;map[cy][cx] == '1' && cx < n && cy < n;) {
                        cx += dx;
                        cy += dy;
                        c++;
                    }
                    ans = max(ans, c);
                }
            }
        }
        cout << ans << endl;

    }
}

C++: #include <bits/stdc++.h>

using namespace std;

const int MAX_N = 300;
 
int n, cnt;
int in[MAX_N][MAX_N];
int s[MAX_N][MAX_N];
 
void cp_in(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}
 
void dfs(int y, int x, bool bit)
{
    if (bit) {
        if (n <= x || n <= y) return;
        cnt++;
        int nx = x + 1;
        int ny = y + 1;
     
        if (0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1) {
            dfs(ny, nx, bit);
        }
    } else {
        if (x < 0 || n <= y) return;
        cnt++;
        int nx = x - 1;
        int ny = y + 1;
         
        if (0 <= nx && nx < n && 0 <= ny && ny < n && s[ny][nx] == 1) {
            dfs(ny, nx, bit);
        }
    }
}
 
int main()
{
    char ch;
    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 >> ch;
                in[i][j] = ch - '0';
            }
        }
        for (int i = 0; i < n; i++) {
            cnt = 0;
            for (int j = 0; j < n; j++) {
                if (in[i][j] == 1) {
                    cnt++;
                    a = max(a, cnt);
                } else {
                    cnt = 0;
                }
            }
        }
         
        for (int i = 0; i < n; i++) {
            cnt = 0;
            for (int j = 0; j < n; j++) {
                if (in[j][i] == 1) {
                    cnt++;
                    b = max(b, cnt);
                } else {
                    cnt = 0;
                }
            }
        }
 
        cp_in();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cnt = 0;
                if (s[i][j] == 1) dfs(i, j, 1);
                c = max(c, cnt);
            }
        }
         
        cp_in();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                cnt = 0;
                if (s[i][j] == 1) dfs(i, j, 0);
                d = max(d, cnt);
            }
        }    
        cout << max(max(a, b), max(c, d)) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	int field[256][256];
	while(cin>>n&&n!=0){
		int maxLength=0;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				char ch;
				cin>>ch;
				field[i][j]=ch-'0';
			}
		}
		for(int i = 0; i < n; i++){
			int len=0;
			for(int j = 0; j < n; j++){
				if(field[i][j]==1){
					len++;
					maxLength=max(maxLength,len);
				}
				else{
					len=0;
				}
			}
		}
		for(int i = 0; i < n; i++){
			int len=0;
			for(int j = 0; j < n; j++){
				if(field[j][i]==1){
					len++;
					maxLength=max(maxLength,len);
				}
				else{
					len=0;
				}
			}
		}
		// ÈÈß
		for(int j = 0; j < n; j++){
			int len=0;
			int cy=0;
			int cx=j;
			while(1){
				if(field[cy][cx]==1){
					len++;
					maxLength=max(maxLength,len);
				}
				else{
					len=0;
				}
				int ny=cy+1;
				int nx=cx-1;
				if(!(ny>=0&&nx>=0&&ny<n&&nx<n)){
					break;
				}
				cx=nx;
				cy=ny;
			}
		}
		// ÈÈß
		for(int j = 0; j < n; j++){
			int len=0;
			int cy=0;
			int cx=j;
			while(1){
				if(field[cy][cx]==1){
					len++;
					maxLength=max(maxLength,len);
				}
				else{
					len=0;
				}
				int ny=cy+1;
				int nx=cx+1;
				if(!(ny>=0&&nx>=0&&ny<n&&nx<n)){
					break;
				}
				cx=nx;
				cy=ny;
			}
		}
		cout<<maxLength<<endl;
	}


	return 0;
}

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