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 <algorithm>
using namespace std;
int dx[] = {-1,-1,-1,0,0,1,1,1},dy[] = {-1,0,1,-1,1,-1,0,1};
int ans;
int n;
char ma[100][100];

void cheak(int px,int dx,int py,int dy){
  int cnt = 1;

  while(1){
    px+=dx;
    py+=dy;
    if(!(0<=px && px < n && 0 <= py && py < n) || ma[py][px] != '1')break;
    cnt++;
  }
  ans = max(ans,cnt);
}

int main(){
  while( cin >> n,n){

    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ;  j < n ; j++){
	cin >> ma[i][j];
      }
    }

    ans = 0;

    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ;  j < n ; j++){

	if(ma[i][j] == '1'){
	  for(int l = 0 ; l < 8; l++){
	      cheak(j,dx[l],i,dy[l]);
	  }
	}

      }
    }
    cout << ans << endl;
  }
}

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

C++: #include<stdio.h>
#define MAX 255
#define FOR(i,m,n) for(i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
int max(int a,int b){return a>b?a:b;}
int main(void)
{
  int n,i,j,res;
  char F[MAX][MAX],r[MAX][MAX],l[MAX][MAX],u[MAX][MAX],rl[MAX][MAX],t;
  for(;;){
    scanf("%d",&n); if(!n)break;
    res=0;
    rep(i,n)rep(j,n){
      scanf(" %c ",F[i]+j);
      F[i][j]^='0';
      rl[i][j]=u[i][j]=r[i][j]=l[i][j]=F[i][j]?1:0;
      if(F[i][j])res=1;
    }
    rep(i,n)rep(j,n){
      if(F[i][j]){
        if(i&&j+1<n&&r[i-1][j+1]){
          r[i][j]=r[i-1][j+1]+1;
        }
        if(i&&j&&l[i-1][j-1]){
          l[i][j]=l[i-1][j-1]+1;
        }
        if(i&&u[i-1][j]){
          u[i][j]=u[i-1][j]+1;
        }
        if(j&&rl[i][j-1]){
          rl[i][j]=rl[i][j-1]+1;
        }
      }
      else{
        l[i][j]=0;
        r[i][j]=0;        
        u[i][j]=0;
        rl[i][j]=0;
      }
      res=max(max(res,max(rl[i][j],u[i][j])),max(r[i][j],l[i][j]));
    }
    printf("%d\n",res);
  }
  return 0;
}

C++: #include<stdio.h>
char table1[255][256];
int slash[255][255];
int yen[255][255];
int yoko[255][255];
int tate[255][255];
int main(){
	int n;
	while(scanf("%d",&n),n){
		for(int i=0;i<255;i++)
			for(int j=0;j<255;j++)
				table1[i][j]='0';
		for(int i=0;i<n;i++){
			scanf("%s",table1[i]);
		}
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				yen[i][j]=slash[i][j]=tate[i][j]=yoko[i][j]=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(i==0&&table1[i][j]=='1')tate[i][j]=1;
				else if(i>0&&table1[i][j]=='1')tate[i][j]=tate[i-1][j]+1;
				if(j==0&&table1[i][j]=='1')yoko[i][j]=1;
				else if(j>0&&table1[i][j]=='1')yoko[i][j]=yoko[i][j-1]+1;
				if((i==0||j==0)&&table1[i][j]=='1')yen[i][j]=1;
				else if(table1[i][j]=='1')yen[i][j]=yen[i-1][j-1]+1;
			}
		}
		for(int i=n-1;i>=0;i--){
			for(int j=0;j<n;j++){
				if((i==n-1||j==n-1)&&table1[i][j]=='1')slash[i][j]=1;
				else if(table1[i][j]=='1')slash[i][j]=slash[i+1][j+1]+1;
			}
		}
		int ret=0;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++){
				if(ret<yen[i][j])ret=yen[i][j];
				if(ret<slash[i][j])ret=slash[i][j];
				if(ret<yoko[i][j])ret=yoko[i][j];
				if(ret<tate[i][j])ret=tate[i][j];
			}
		printf("%d\n",ret);
	}
}

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

int n;
string field[256];

int vertical(int y, int x){
  int cnt = 0;
  while(1){
    if(y >= n || field[y][x] == '0') break;
    y++;
    cnt++;
  }
  return cnt;
}

int horizonal(int y, int x){
  int cnt = 0;
  while(1){
    if(x >= n || field[y][x] == '0') break;
    x++;
    cnt++;
  }
  return cnt;
}

int diagonal_left(int y, int x){
  int cnt = 0;
  while(1){
    if(x < 0 || y >= n || field[y][x] == '0') break;
    x--, y++;
    cnt++;
  }
  return cnt;
}

int diagonal_right(int y, int x){
  int cnt = 0;
  while(1){
    if(x >= n || y >= n || field[y][x] == '0') break;
    x++, y++;
    cnt++;
  }
  return cnt;
}

int main(){
  while(cin >> n, n){
    for(int i = 0 ; i < n ; i++){
      cin >> field[i];
    }
    
    int ans = 0;
    
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < n ; j++){
	if(field[i][j] == '1'){
	  ans = max(ans, vertical(i, j));
	  ans = max(ans, horizonal(i, j));
	  ans = max(ans, diagonal_left(i, j));
	  ans = max(ans, diagonal_right(i, j));
	} 
      }
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back

int n;
int main(){
    int n;
    while(cin>>n&&n){
        int dp[256][256][4];
        rep(i,256)rep(j,256)rep(k,4)dp[i][j][k] = 0;

        vector<string> data(n);
        rep(i,n)cin>>data[i];
        
        int maxi = 0;
        rep(i,n){
            rep(j,n){
                if(data[i][j]=='1'){
                    dp[i][j][0] = ( j-1>=0          )*dp[i  ][j-1][0] +1;
                    dp[i][j][1] = ( i-1>=0          )*dp[i-1][j  ][1] +1;
                    dp[i][j][2] = ( i-1>=0&&j-1>=0  )*dp[i-1][j-1][2] +1;
                    dp[i][j][3] = ( i-1>=0&&j+1<n   )*dp[i-1][j+1][3] +1;

                    rep(k,4) maxi = max(maxi,dp[i][j][k]);
                }
            }
        }
        cout<<maxi<<endl;
    }
}