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>
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};
string str[MAX_N],s[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] = str[i][j];
        }
    }
}

int main(){
    while(cin >> n ,n){
        int a = 0,b = 0,c = 0,d = 0;
        for(int i = 0 ; i < n ; i++){
            cin >> str[i];
        }
        
        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;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int n,ma;
	while(cin>>n,n){
		string s[260];
		rep(i,n)
		cin>>s[i];
		ma=0;
		rep(i,n){
			rep(j,n){
				if(s[i][j]=='1')
					for(int k=j;;k++){
						if(s[i][k]=='0'||k==n){
							ma=max(ma,k-j);
							j=k;
							
							break;
						}
					}
			}
			rep(j,n){
				if(s[j][i]=='1')
					for(int k=0;;k++){
						if(s[j+k][i]=='0'||k+j==n){
							ma=max(ma,k-j);
							j=k;
							break;
						}
					}
				
			}
			
			rep(j,n){
				if(s[i][j]=='1'){
					for(int k=0;;k++){
							if(s[i+k][j+k]=='0'||k+i==n||k+j==n){
								ma=max(ma,k);
								break;
							}
					}
					
					for(int k=0;;k++){
						if(i+k==n||j-k==-1||s[i+k][j-k]=='0'){
								ma=max(ma,k);
								break;
						}
					}
				}
			}
			
			
			
			
			
			
			
		}
		cout<<ma<<endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[300][300],d=0,f=0,g,h,j,i,k;
	char z[300][300];
	while(1){
		f=0;
		scanf("%d",&a);
		if(a==0) break;
		for(i=0;i<a;i++)
			scanf("%s",z[i]);
		for(i=0;i<a;i++){
			for(j=0;j<a;j++){
				if(z[i][j]=='1'){
					for(k=0;k<a;k++){
						if(i-k==-1||j+k==a) break;
						if(z[i-k][j+k]=='1') d++;
						else break;
					}
					if(f<d) f=d;
					d=0;
					for(k=0;k<a;k++){
						if(i+k==a||j+k==a) break;
						if(z[i+k][j+k]=='1') d++;
						else break;
					}
					if(f<d) f=d;
					d=0;
					for(k=0;k<a;k++){
						if(i+k==a) break;
						if(z[i+k][j]=='1') d++;
						else break;
					}
					if(f<d) f=d;
					d=0;
					for(k=0;k<a;k++){
						if(j+k==a) break;
						if(z[i][j+k]=='1') d++;
						else break;
					}
					if(f<d) f=d;
					d=0;
				}
			}
		}
		printf("%d\n",f);
	}
	return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		vector<string> field;
		for (int i = 0; i < n; i++) {
			string s; cin >> s;
			field.push_back(s);
		}

		// 横 
		int max_len = 0;
		for (int i = 0; i < n; i++) {
			int cur_len = 0;
			for (int j = 0; j < n; j++) {
				if (field[i][j] == '1') {
					cur_len++;
				} else {
					max_len = max(cur_len, max_len);
					cur_len = 0;
				}
			}
			max_len = max(cur_len, max_len);
		}

		// 縦
		for (int i = 0; i < n; i++) {
			int cur_len = 0;
			for (int j = 0; j < n; j++) {
				if (field[j][i] == '1') {
					cur_len++;
				} else {
					max_len = max(cur_len, max_len);
					cur_len = 0;
				}
			}
			max_len = max(cur_len, max_len);
		}

		// 斜め, 右上->左下
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int cur_len = 0;
				for (int k = i, l = j; k < n && l < n; k++, l++) {
					if (field[k][l] == '1') {
						cur_len++;
					} else {
						max_len = max(cur_len, max_len);
						cur_len = 0;
					}
				}
				max_len = max(cur_len, max_len);
			}
		}

		// 斜め, 左上->右下
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				int cur_len = 0;
				for (int k = i, l = j; k < n && 0 <= l; k++, l--) {
					if (field[k][l] == '1') {
						cur_len++;
					} else {
						max_len = max(cur_len, max_len);
						cur_len = 0;
					}
				}
				max_len = max(cur_len, max_len);
			}
		}

		cout << max_len << endl;
	}
	return 0;
}