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;

typedef long long ll;
typedef pair<int, int> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  while(cin >> n) {
    if(!n) return 0;
    string g[n] = {};

    rep(i, 0, n) {
      cin >> g[i];
    }
    int ma = 0;

    rep(i, 0, n) {
      int s = 0, ss = 0;
      rep(j, 0, n) if(g[i][j] == '1') s++;
      rep(j, 0, n) if(g[j][i] == '1') ss++;
      ma = max(ma, max(s, ss));
    }

    rep(i, 0, n) {
      int x = i, y = 0;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x += 1, y += 1;
        if(x == n || y == n) break;
      }
      x = i, y = 0;
      while(1) {
        if(g[x][y] == '1') ss++;
        x -= 1, y += 1;
        if(x == -1 || y == n) break;
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = i, y = n - 1;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x += 1, y -= 1;
        if(x == n || y == -1) break;
      }
      x = i, y = n - 1;
      while(1) {
        if(g[x][y] == '1') ss++;
        x -= 1, y -= 1;
        if(x == -1 || y == -1) break;
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = 0, y = i;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x += 1, y += 1;
        if(x == n || y == n) break;
      }
      x = 0, y = i;
      while(1) {
        if(g[x][y] == '1') ss++;
        x += 1, y -= 1;
        if(x == n || y == -1) break;
      }
      ma = max(ma, max(s, ss));
    }


    rep(i, 0, n) {
      int x = n - 1, y = i;
      int s = 0, ss = 0;
      while(1) {
        if(g[x][y] == '1') s++;
        x -= 1, y += 1;
        if(x == -1 || y == n) break;
      }
      x = n - 1, y = i;
      while(1) {
        if(g[x][y] == '1') ss++;
        x -= 1, y -= 1;
        if(x == 0 || y == 0) break;
      }
      ma = max(ma, max(s, ss));
    }

    cout << ma << endl;
  }
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
const int MAX_N = 300;

int n,cnt;
int in[MAX_N][MAX_N];
int s[MAX_N][MAX_N];

void dfs(int y,int x,bool bit){
    if(bit){
        if(n <= x || n <= y) return;
        s[y][x] = 0;
        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;
        s[y][x] = 0;
        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);
        }
    }
}

void cp_in(){
    for(int i = 0 ; i < n ; i++){
        for(int j = 0 ; j < n ; j++){
            s[i][j] = in[i][j];
        }
    }
}

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++){
                cnt = 0;
                if(s[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<algorithm>
#include<string>
using namespace std;

int main(){

  string s[10000];
  int n,x,y,k,ans;

  while(cin >> n, n){

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

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	ans = 0;
	for(x=i,y=j;y<n;y++){
	  if(s[x][y] != '1') break;
	  ans++;
	  k = max(k,ans);
	}

	ans = 0;
	for(x=i,y=j;x>=0;x--){
	  if(s[x][y] != '1') break;
	  ans++;
	  k = max(k,ans);
	}

	x = i;
	y = j;
       	ans = 0;
	while(x >= 0 && y < n){
	  if(s[x][y] != '1') break;
	  ans++;
	  x--;
	  y++;
	  k = max(k,ans);
	}

	x = i;
	y = j;
	ans = 0;
	while(x >= 0 && y >= 0){
	  if(s[x][y] != '1') break;
	  ans++;
	  x--;
	  y--;
	  k = max(k,ans);
	}

      }
    }

    cout << k << endl;
  }
}

C++: #include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int n;
	int MAX,sum;
	
	while(cin >> n && n){
		MAX = 0;
		
		char p[n*n+1];
		rep(i,n*n){cin >> p[i];p[i]-='0';}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i*n+j];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n)sum += p[i+j*n];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[i+j*(n+1)];
			MAX = max(sum,MAX);
		}
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[(n-1-i)+j*(n-1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,n-i)sum += p[n*n-1-i-j*(n+1)];
			MAX = max(sum,MAX);
		}
		
		rep(i,n){
			sum = 0;
			rep(j,i+1)sum += p[n*(n-1)+i-j*(n-1)];
			MAX = max(sum,MAX);
		}
		cout << MAX << endl;
	}
}