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>
#define UE 0
#define SHITA 1
#define MIGI 2
#define HIDARI 3
#define N_U_MIGI 4
#define N_S_MIGI 5
#define N_U_HIDARI 6
#define N_S_HIDARI 7
using namespace std;

const int MAX_N = 260;
void loop(string v[], int y, int x, int type, int n, int deep);
int tmp;

int main(){
	int n;
	while(cin >>n){
		if(n == 0) break;
		string v[MAX_N];
		int max = 0;
		for(int i = 0; i < n; i++){
			cin >>v[i];
		}
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				if(v[i][j] == '1'){
					int u, s, m, h, num, nsm, nuh, nsh;
					//cout <<"v[" <<i <<"][" <<j <<"] = 1" <<endl;
					
					tmp = 0; loop(v, i, j, UE, n, 0);
					u = tmp;
					
					tmp = 0; loop(v, i, j, SHITA, n, 0);
					s = tmp;
					
					tmp = 0; loop(v, i, j, MIGI, n, 0);
					m = tmp;
					
					tmp = 0; loop(v, i, j, HIDARI, n, 0);
					h = tmp;
					
					tmp = 0; loop(v, i, j, N_U_MIGI, n, 0);
					num = tmp;
					
					tmp = 0; loop(v, i, j, N_S_MIGI, n, 0);
					nsm = tmp;
					
					tmp = 0; loop(v, i, j, N_U_HIDARI, n, 0);
					nuh = tmp;
					
					tmp = 0; loop(v, i, j, N_S_HIDARI, n, 0);
					nsh = tmp;
					
					//cout <<"u + s = " <<u + s + 1 <<endl;
					//cout <<"m + h = " <<m + h + 1 <<endl;
					//cout <<"num + nsh = " <<num + nsh + 1 <<endl;
					//cout <<"nuh + nsm = " <<nuh + nsm + 1 <<endl;
					
					if(max < u + s + 1){
						max = u + s + 1;
					} if(max < m + h + 1){
						max = m + h + 1;
					} if(max < num + nsh + 1){
						max = num + nsh + 1;
					} if(max < nuh + nsm + 1){
						max = nuh + nsm + 1;
					}
					//cout <<"max = " <<max <<endl;
					
				}
			}
		}
		cout <<max <<endl;
	}
	return 0;
}

void loop(string v[], int y, int x, int type, int n, int deep){
	int plusx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, plusy[8] = {-1, 1, 0, 0, -1, 1, -1, 1};
	if(x < 0 || y < 0 || x >= n || y >= n || v[y][x] == '0'){
		//cout <<"x = " <<x <<" y = " <<y <<" deep - 1 = " <<deep - 1 <<endl;
		tmp += (deep - 1);
	} else{
		loop(v, (y + plusy[type]), (x + plusx[type]), type, n, deep + 1);
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            char a;
            std::vector<vector<char>> vec(n,vector<char>(n));
            for (int i=0;i<n;i++) {
                for (int j=0;j<n;j++) {
                    cin>>a;
                    vec.at(i).at(j)=a;
                }
            }
            int countVer=0,countSide=0,countDiaLeft=0,countDiaRight=0,maxCount=0;
            for (int l=0;l<n;l++) {
                for (int m=0;m<n;m++) {
                    if (vec.at(l).at(m)=='1') {
                        int tmp1=l;
                        int tmp2=m;
                        //横探索
                        while (tmp2!=n&&vec.at(tmp1).at(tmp2)=='1') {
                            countSide++;
                            tmp2++;
                        }
                        tmp1=l;
                        tmp2=m;
                        //縦探索
                        while (tmp1!=n&&vec.at(tmp1).at(tmp2)=='1') {
                        countVer++;
                        tmp1++;
                        }
                        tmp1=l;
                        tmp2=m;
                        //左斜め探索
                        while (tmp1!=n&&tmp2!=-1&&vec.at(tmp1).at(tmp2)=='1') {
                            countDiaLeft++;
                            tmp1++;
                            tmp2--;
                        }
                        //右斜め探索
                        tmp1=l;
                        tmp2=m;
                        while (tmp1!=n&&tmp2!=n&&vec.at(tmp1).at(tmp2)=='1') {
                            countDiaRight++;
                            tmp1++;
                            tmp2++;
                        }
                        int ans=max(countVer,max(countSide,max(countDiaLeft,countDiaRight)));
                        if (ans>maxCount) {
                            maxCount=ans;
                        }
                        countVer=0,countSide=0,countDiaLeft=0,countDiaRight=0;
                    }
                }
            }
            cout<<maxCount<<endl;
        }
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second


int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  int n;
  while(cin>>n,n){
    int grid[n][n],tate[n][n],yoko[n][n],lurd[n][n],ruld[n][n];
    char c;
    rep(i,n)rep(j,n){
      cin>>c;
      tate[i][j]=yoko[i][j]=lurd[i][j]=ruld[i][j]=grid[i][j]=c-'0';
    }
    

    int ans=0;
    rep(i,n){
      rep(j,n){
	if(grid[i][j]==0)continue;
	if(i&&j+1<n&&ruld[i-1][j+1])ruld[i][j]=max(ruld[i][j],ruld[i-1][j+1]+1);
	if(i&&tate[i-1][j])tate[i][j]=max(tate[i][j],tate[i-1][j]+1);
	if(i&&j&&lurd[i-1][j-1])lurd[i][j]=max(lurd[i][j],lurd[i-1][j-1]+1);
	if(i&&yoko[i][j-1])yoko[i][j]=max(yoko[i][j],yoko[i][j-1]+1);
	ans=max(ans,max(tate[i][j],max(yoko[i][j],max(lurd[i][j],ruld[i][j]))));
      }
    }
    rep(i,n){
      rep(j,n){
	//	printf("%2d",grid[i][j]);
      }
      //      cout<<endl;
    }
    cout<<ans<<endl;
  }
}

C++: #include<cstdio.h>
#include<iostream>
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;
}