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

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

int main(){
	int n;
	while( cin >> n , n ){
		string f[256];
		int ans = 0;

		for(int i=0 ; i < n ; i++ ){
			cin >> f[i];
		}
		for(int y=0 ; y < n ; y++ ){
			for(int x=0 ; x < n ; x++ ){
				if( f[y][x] == '1' ){
					for(int i=0 ; i < 4 ; i++ ){
						int mx = x + dx[i];
						int my = y + dy[i];
						int cnt = 1;
						while( mx >= 0 && my >= 0 && mx < n && my < n && f[my][mx] == '1' ){
							mx += dx[i];
							my += dy[i];
							cnt++;
						}
						ans = max( ans , cnt );
					}
				}
			}
		}
		cout << ans << endl;
	}
}

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

#define M 255

int main() {
  int n, c, t, ans;
  char buf[M+2];
  char a[M][M];
  while (1) {
    scanf("%d\n", &n);
    if (!n) break;

    for (int i=0; i<n; i++) {
      fgets(buf, sizeof(buf), stdin);
      for (int j=0; j<n; j++) {
        a[i][j] = (buf[j]=='0') ? 0 : 1;
      }
    }

    ans = 0;
    for (int i=0; i<n; i++) {
      c = 0;
      for (int j=0; j<n; j++) {
        if (a[i][j]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int i=0; i<n; i++) {
      c = 0;
      for (int j=0; j<n; j++) {
        if (a[j][i]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int s=0; s<2*n-1; s++) {
      c = 0;
      for (int i=0; i<n; i++) {
        t = s-i;
        if (t>=0 && t<n && a[i][t]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    for (int d=-n+1; d<n; d++) {
      c = 0;
      for (int i=0; i<n; i++) {
        t = i+d;
        if (t>=0 && t<n && a[i][t]) {
          ans = max(ans, ++c);
        } else {
          c = 0;
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin>>n && n){
    vector<vector<char>> vc(n,vector<char>(n,' '));
    rep(i,n){
      rep(j,n){
        cin >>vc[j][i];
        vc[j][i] -= '0';
      }
    }
    vector<vector<ll>> tmp(n,vector<ll>(n,0));
    auto copy = tmp;
    ll ma = 0;
    rep(i,n){
      rep(j,n){
        if( j > 0 && vc[j][i]){
          tmp[j][i] += tmp[j-1][i]+1;
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    tmp = copy;
    rep(j,n){
      rep(i,n){
        if( i > 0 && vc[j][i]){
          tmp[j][i] += tmp[j][i-1]+1;
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    //??????->??????
    tmp = copy;
    rep(i,n){
      rep(j,n){
        if( j < n-1 && i > 0&& vc[j][i]){
          tmp[j][i] += tmp[j+1][i-1]+1;
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    //??????->??????
    tmp = copy;
    rep(i,n){
      rep(j,n){
        if( j > 0 && i > 0 && vc[j][i]){
          tmp[j][i] += tmp[j-1][i-1]+1;
        }
        ma = max(ma,tmp[j][i]);
      }
    }
    cout << ma << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int calc(int nb[256][256], int n, int ret) {
	rep(i,n) {
		rep(j,n) {
			if(ret<nb[i][j]) ret = nb[i][j];		
		}
	}
	return ret;
}

int main() {
	int n;
	string s;
	while(cin >> n, n) {
		int b[256][256] = {};
		int nb[256][256] = {};
		rep(i,n) {
			cin >> s;
			rep(j,n) {
				b[i][j] = s[j]-'0';
			}
		}
		int ret = 0;
		rep(i,n) {
			rep(j,n) {
				if(i==0) {
					nb[i][j] = b[i][j];
					continue;
				}
				nb[i][j] = b[i][j] ? nb[i-1][j]+b[i][j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		rep(i,n) {
			rep(j,n) {
				if(j==0) {
					nb[i][j] = b[i][j];
					continue;
				}
				nb[i][j] = b[i][j] ? nb[i][j-1]+b[i][j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		rep(i,2*n) {
			int k = i<n?i:2*n-i;
			rep(j,k) {
				if(j==0) {
					if(i<n) nb[n-i][0] = b[n-i][0];
					else nb[0][i-n] = b[0][i-n];
					continue;
				}
				if(i<n) nb[n-i+j][j] = b[n-i+j][j] ? nb[n-i+j-1][j-1]+b[n-i+j][j] : 0;
				else nb[j][i-n+j] = b[j][i-n+j] ? nb[j-1][i-n+j-1]+b[j][i-n+j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		rep(i,2*n) {
			int k = i<n?i:2*n-i;
			rep(j,k) {
				if(j==0) {
					if(i<n) nb[n-i][n-1] = b[n-i][n-1];
					else nb[0][2*n-1-i] = b[0][2*n-1-i];
					continue;
				}
				if(i<n) nb[n-i+j][n-1-j] = b[n-i+j][n-1-j] ? nb[n-i+j-1][n-j]+b[n-i+j][n-1-j] : 0;
				else nb[j][2*n-1-i-j] = b[j][2*n-1-i-j] ? nb[j-1][2*n-i-j]+b[j][2*n-1-i-j] : 0;
			}
		}
		ret = calc(nb,n,ret);
		cout << ret << endl;
	}
	return 0;
}