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

int main(void){
  int n;
  string l;
  int retval;
  int r,d,ld,rd;
  while(1){
    cin>>n;
    if(n==0)break;
    int grid[n+2][n+2];
    for(int i=0;i<n+2;i++){
      grid[i][0]=0;
      grid[0][i]=0;
      grid[i][n+1]=0;
      grid[n+1][i]=0;
    }
    for(int i=1;i<n+1;i++){
      cin>>l;
      for(int j=1;j<n+1;j++){
        grid[i][j]=l[j-1];
      }
    }
    retval=0;
    for(int i=1;i<n+1;i++){
      for(int j=1;j<n+1;j++){
        if(grid[i][j]=='0')continue;

        d=0;
        while(1){
          if(grid[i+d][j]=='1'){
            d++;
          }
          else{
            break;
          }
        }
        retval=max(retval,d);
        r=0;
        while(1){
          if(grid[i][j+r]=='1'){
            r++;
          }
          else{
            break;
          }
        }
        retval=max(retval,r);

        ld=0;
        while(1){
          if(grid[i+ld][j-ld]=='1'){
            ld++;
          }
          else{
            break;
          }
        }
        retval=max(retval,ld);

        rd=0;
        while(1){
          if(grid[i+rd][j+rd]=='1'){
            rd++;
          }
          else{
            break;
          }
        }
        retval=max(retval,rd);
      }
    }
    cout<<retval<<endl;
  }
}

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

int search(int x, int y, int k, int n, char** field) {
    int nx, ny;
    switch (k) {
    case 0:
        nx = x + 1;
        ny = y;
        break;
    case 1:
        nx = x + 1;
        ny = y + 1;
        break;
    case 2:
        nx = x;
        ny = y + 1;
        break;
    case 3:
        nx = x - 1;
        ny = y + 1;
        break;
    }
    if (0 <= nx && nx < n && 0 <= ny && ny < n && field[ny][nx] != '0') {
        return 1 + search(nx, ny, k, n, field);
    } else {
        return 1;
    }
}

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        char** field = new char* [n];
        for (int i = 0; i < n; i++) {
            field[i] = new char [n + 1];
        }
        for (int i = 0; i < n; i++) {
            cin >> field[i];
        }

        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (field[i][j] == '0') {
                    continue;
                }
                for (int k = 0; k < 4; k++) {
                    int length = search(j, i, k, n, field);
                    if (max < length) {
                        max = length;
                    }
                }
            }
        }
        cout << max << endl;
        for (int i = 0; i < n; i++) {
            delete[] field[i];
        }
        delete[] field;
    }
}

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

int main(){
  int n;
  int field[255][255];
  int d;
  string tmp;

  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++){
      cin >> tmp;
      for(int j=0;j<n;j++)field[i][j] = tmp[j]-'0';
    }

    int ans = 0;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(field[i][j]){
	  d = 1;
	  while(i+d<n &&  j-d>=0 && field[i+d][j-d])d++;
	  ans = max(ans,d);

	  d = 1;
	  while(i+d<n && field[i+d][j])d++;
	  ans = max(ans,d);

	  d = 1;
	  while(i+d<n && j+d<n && field[i+d][j+d])d++;
	  ans = max(ans,d);

	  d = 1;
	  while(j+d<n && field[i][j+d])d++;
	  ans = max(ans,d);

	}
      }
    }

    cout << ans << endl;
  }
}

C++: #include <bits/stdc++.h>

using namespace std;

int MapData[255][255], DpResult[4][255][255], Ans[4], MaxLen;
string strOfRow;

void solve(int n) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (MapData[i][j] == 0) {
				continue;
			}

			//上下
			if (i > 0) {
				DpResult[0][i][j] = DpResult[0][i - 1][j] + 1;
			}
			//左右
			if (j > 0) {
				DpResult[1][i][j] = DpResult[1][i][j - 1] + 1;
			}
			//左斜め
			if (i > 0 && j > 0) {
				DpResult[2][i][j] = DpResult[2][i - 1][j - 1] + 1;
			}
			//右斜め
			if (i > 0 && j < n-1) {
				DpResult[3][i][j] = DpResult[3][i - 1][j + 1] + 1;
			}

			for (int k = 0; k < 4; k++) {
				Ans[k] = max(Ans[k], DpResult[k][i][j]);
				MaxLen = max(MaxLen, Ans[k]);
			}
		}
	}
	
}

void show(int n) {
	cout << "Dp:" << endl;
	for (int k = 0; k < 4; k++) {
		cout << "k=" << k << endl;
		for (int row = 0; row < n; row++) {
			for (int j = 0; j < n; j++) {
				cout << DpResult[k][row][j];
			}
			cout << endl;
		}
		cout << "ans=" << Ans[k] << endl << endl;
	}
}

int main() {
	int n;

	while (cin >> n, n) {
		memset(MapData, 0, sizeof(MapData));
		memset(DpResult, 0, sizeof(DpResult));
		memset(Ans, 0, sizeof(Ans));
		MaxLen = 0;
		for (int row = 0; row < n; row++) {
			cin >> strOfRow;
			for (int col = 0; col < n; col++) {
				MapData[row][col] = DpResult[0][row][col] = DpResult[1][row][col] = DpResult[2][row][col] = DpResult[3][row][col] = strOfRow[col] - '0';
			}			
		}
		solve(n);
		//show(n);
		cout << MaxLen << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;

int maxi = 0;


int main(){
	int n;
	while(scanf("%d",&n)==1,n){
		vector<string> mat;
		maxi = 0;
		char el[n+5];
		for(int x=0;x<n;++x){
			scanf("%s",el);
			string ss(el);
			mat.push_back(ss);
		}
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				int x=i,y=j,tmp = 0;
				while(y>=0 && x<n && mat[x][y]=='1'){
					tmp++;--y;++x;
				}
				maxi = max(tmp,maxi);
				x=i;y=j;tmp=0;
				while(x<n && mat[x][y]=='1'){
					tmp++;++x;
				}
				maxi = max(tmp,maxi);
				x=i;y=j;tmp=0;
				while(y<n && mat[x][y]=='1'){
					++tmp;++y;
				}
				maxi = max(tmp,maxi);
				x=i;y=j;tmp=0;
				while(x<n && y<n && mat[x][y]=='1'){
					++tmp;++x;++y;
				}
				maxi = max(tmp,maxi);
			}
		}
		cout<<maxi<<endl;	
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int i,j,k,n,max,cnt,x,y,
		dx[]={1,1,0,-1},dy[]={0,1,1,1};
	char xy[255][256];
	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) break;
							if(xy[y][x]!='1')break;
							cnt++;
						}
						if(max<cnt) max=cnt;
					}
				}
			}
		}
		cout<<max<<endl;
	}
	return 0;
}