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 <bits/stdc++.h>
using namespace std;

int n;

int getMax(vector< vector<int> > f){
  int ma = 0;
  for(int i=0; i < n; i++){
    for(int j=0; j < n; j++){
      ma = max(ma, f[i][j]);
    }
  }
  return ma;
}

int main(void){
  while(cin >> n, n){
    vector< vector <int> > table(n, vector<int>(n));
    for(int i=0; i < n; i++){
      string tmp;
      cin >> tmp;
      for(int j=0; j < n; j++){
        table[i][j] = tmp[j] - '0';
      }
    }

    vector< vector <int> > h  = table;
    vector< vector <int> > v  = table;
    vector< vector <int> > l1 = table;
    vector< vector <int> > l2 = table;


    for(int p = 0; p < n; p++){
      for(int q = 1; q < n; q++){
        if(table[p][q] == 1){
          h[p][q] = h[p][q-1] + 1;
        }
      }
    }
    for(int p = 1; p < n; p++){
      for(int q = 0; q < n; q++){
        if(table[p][q] == 1){
          v[p][q] = v[p-1][q] + 1;
        }
      }
    }
    for(int p = 1; p < n; p++){
      for(int q = 1; q < n; q++){
        if(table[p][q] == 1){
          l1[p][q] = l1[p-1][q-1] + 1;
        }
      }
    }
    for(int p = 1; p < n; p++){
      for(int q = 0; q < n-1; q++){
        if(table[p][q] == 1){
          l2[p][q] = l2[p-1][q+1] + 1;
        }
      }
    }

    vector<int> kouho(4, 0);
    kouho[0] = getMax(h); 
    kouho[1] = getMax(v); 
    kouho[2] = getMax(l1); 
    kouho[3] = getMax(l2); 

    cout << *max_element(kouho.begin(), kouho.end()) << endl;

  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
using namespace std;

#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()

int main() {
  int n;
  while(cin >> n, n) {
    char ba[n][n];
    REP(i,n)
      REP(j,n)
      cin >> ba[j][i];
    int dp[n][n][4]; // ツ可。ツ、ツ縦ツ、ツ偲篠湘」ツ債カツ、ツ偲篠湘」ツ右
    memset(dp,0,sizeof(dp));
    
    REP(y,n) {
      REP(x,n) {
        if (ba[x][y] == '1') {
          dp[x][y][0] = ((x>0)?dp[x-1][y][0]:0) + 1;
          dp[x][y][1] = ((y>0)?dp[x][y-1][1]:0) + 1;
          dp[x][y][2] = ((x>0&&y>0)?dp[x-1][y-1][2]:0) + 1;
          dp[x][y][3] = ((x<n-1&&y>0)?dp[x+1][y-1][3]:0) + 1;
        }
      }
    }
    cout << *max_element(&dp[0][0][0],&dp[n-1][n-1][3]) << endl;
  }
}

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

int n, m, t;
char s[255][256];

void check(int i, int j) {
	if (s[i][j] == '1') {
		t++;
		m = max(m, t);
	}
	else
		t = 0;
}

int main()
{	
	cin >> n;

	while (n > 0) {
		memset(s, 0, sizeof(s));

		for (int i = 0; i < n; i++)
			cin >> s[i];

		m = 0;
	
		for (int i = 0; i < n; i++) {
			t = 0;
			for (int j = 0; j < n; j++)
				check(i, j);
		}

		for (int i = 0; i < n; i++) {
			t = 0;
			for (int j = 0; j < n; j++)
				check(j, i);
		}

		for (int i = 0; i < n * 2 - 1; i++) {
			t = 0;
			for (int j = max(0, i - n); j <= min(i, n - 1); j++)
				check(i - j, j);
		}

		for (int i = 0; i < n * 2 - 1; i++) {
			t = 0;
			for (int j = max(0, n - 1 - i); j <= min(n - 1, n * 2 - 2 - i); j++)
				check(j, j + i - n + 1);
		}

		cout << m << endl;

		cin >> n;
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  while(1){
    int n,ans=0;
    scanf("%d\n",&n);
    if(n==0){
      return 0;
    }
    int i,j,k,a[300][300],b[300][300];
    char s;
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        b[i][j]=0;
      }
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
        scanf("%c",&s);
        a[i][j]=s-'0';
      }
      scanf("\n");
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
        if(a[i][j]==1){
          b[i][j+1]=b[i][j]+1;
        }
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        ans=max(ans,b[i][j]);
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        b[i][j]=0;
      }
    }
    for(i=1;i<=n;i++){
      for(j=1;j<=n;j++){
        if(a[j][i]==1){
          b[j+1][i]=b[j][i]+1;
        }
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        ans=max(ans,b[i][j]);
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        b[i][j]=0;
      }
    }
    for(i=1;i<=n;i=k){
      k=i+1;
      for(j=1;j<=n && i>0;i--,j++){
        if(a[i][j]==1){
          b[i-1][j+1]=b[i][j]+1;
        }
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        ans=max(ans,b[i][j]);
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        b[i][j]=0;
      }
    }
    for(i=1;i<=n;i=k){
      k=i+1;
      for(j=1;j<=n && i<=n;i++,j++){
        if(a[i][j]==1){
          b[i+1][j+1]=b[i][j]+1;
        }
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        ans=max(ans,b[i][j]);
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        b[i][j]=0;
      }
    }
    for(i=1;i<=n;i=k){
      k=i+1;
      for(j=n;j>0 && i<=n;i++,j--){
        if(a[i][j]==1){
          b[i+1][j-1]=b[i][j]+1;
        }
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        ans=max(ans,b[i][j]);
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        b[i][j]=0;
      }
    }
    for(i=1;i<=n;i=k){
      k=i+1;
      for(j=n;j>0 && i>0;i--,j--){
        if(a[i][j]==1){
          b[i-1][j-1]=b[i][j]+1;
        }
      }
    }
    for(i=0;i<=n+1;i++){
      for(j=0;j<=n+1;j++){
        ans=max(ans,b[i][j]);
      }
    }
    cout << ans << endl;
  }
}