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 <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

int n;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= n-1 && col >= 0 && col <= n-1)return true;
	return false;
}


int main(){

   int max,tmp,row,col,tmp_row,tmp_col;
   char table[255][256];

   while(true){
	   scanf("%d",&n);
	   if(n == 0)break;

	   for(int i=0; i < n; i++){
		   scanf("%s",table[i]);
	   }

	   max = 0;

	   //?¨???????????????§??????
	   for(int i=0; i < n; i++){
		   tmp = 0;
		   for(int k=0;k < n;k++){
			   if(table[i][k] == '1'){
				   tmp++;
				   if(k == n-1){
					   max = (max >= tmp)?max:tmp;
				   }
			   }
			   else{
				   max = (max >= tmp)?max:tmp;
				   tmp = 0;
			   }
		   }
	   }

	   //?????????????????§??????
	   for(int i=0; i < n; i++){
		   tmp = 0;
		   for(int k= 0; k < n; k++){
			   if(table[k][i] == '1'){
				   tmp++;
				   if(k == n-1){
					   max = (max >= tmp)?max:tmp;
				   }
			   }
			   else{
				   max = (max >= tmp)?max:tmp;
				   tmp = 0;
			   }
		   }
	   }

	   //????????????????????§??????:????§?????????§
	   for(row = 1; row < n;row++){
		   tmp_row = row;
		   col = 0;
		   tmp = 0;
		   while(rangeCheck(tmp_row,col)){
			   if(table[tmp_row][col] == '1'){
				   tmp++;
				   if(rangeCheck(tmp_row-1,col+1) == false){
					   max = (max >= tmp)?max:tmp;
					   tmp = 0;
				   }
			   }
			   else{
				   max = (max >= tmp)?max:tmp;
				   tmp = 0;
			   }
			   tmp_row -= 1;
			   col += 1;
		   }
	   }

	   //????????????????????§??????:????§?????????????
	   for(col = 1;col < n-1; col++){
		   tmp_col = col;
		   row = n-1;
		   tmp = 0;
		   while(rangeCheck(row, tmp_col)){
			   if(table[row][tmp_col] == '1'){
				   tmp++;
				   if(rangeCheck(row-1, tmp_col+1) == false){
					   max = (max >= tmp)?max:tmp;
					  tmp = 0;
				   }
			   }
			   else{
				   max = (max >= tmp)?max:tmp;
				   tmp = 0;
			   }
			   row -= 1;
			   tmp_col += 1;
		   }
	   }

	   //????????????????????§??????:????§?????????§
	   for(row =1; row < n;row++){
		   tmp_row = row;
		   col = n-1;
		   tmp = 0;
		   while(rangeCheck(tmp_row,col)){
			   if(table[tmp_row][col] == '1'){
				   tmp++;
				   if(rangeCheck(tmp_row-1,col-1) == false){
					   max = (max >= tmp)?max:tmp;
					  tmp = 0;
				   }
			   }
			   else{
				   max = (max >= tmp)?max:tmp;
				   tmp = 0;
			   }
			   tmp_row -= 1;
			   col -= 1;
		   }
	   }

	   //????????????????????§??????:????§?????????????
	   for(col = n-2; col > 0; col--){
		   tmp_col = col;
		   row = n-1;
		   tmp = 0;
		   while(rangeCheck(row,tmp_col)){
			   if(table[row][tmp_col] == '1'){
				   tmp++;
				   if(rangeCheck(row-1,tmp_col-1) == false){
					   max = (max >= tmp)?max:tmp;
					  tmp = 0;
				   }
			   }
			   else{
				   max = (max >= tmp)?max:tmp;
				   tmp = 0;
			   }
			   row -= 1;
			   tmp_col -= 1;
		   }
	   }

	   printf("%d\n",max);
   }

    return 0;
}

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

int n;
char a[255][255];


bool in(int y,int x){
	return 0<=y&&y<n&&0<=x&&x<n;
}
int solve(){
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(a[i][j]=='0')continue;
			for(int dy=-1;dy<=1;dy++){
				for(int dx=-1;dx<=1;dx++){
					if(!dy&&!dx)continue;
					int y=i,x=j;
					int seq=0;
					while(in(y,x)&&a[y][x]=='1'){
						seq++;
						y+=dy;
						x+=dx;
					}
					res=max(res,seq);
				}
			}
		}
	}
	return res;
}



int main(){
	while(cin>>n&&n){
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)cin>>a[i][j];
		cout<<solve()<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	while(cin >> n,n){
		int m[4]={0},v[4][2] = {{0,-1},{-1,0},{-1,-1},{1,1}},dp[257][257]={{0,0}};
		char map[257][257];
		for(int y=0;y<257;y++){
			for(int x=0;x<257;x++){
				map[x][y] = '0';
			}
		}
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				cin >> map[x+1][y+1];
			}
		}
		for(int i=0;i<4;i++){
			for(int k=1;k<=n;k++){
				for(int j=1;j<=n;j++){
					dp[j][k] = map[j][k] - '0' + dp[j+v[i][0]][k+v[i][1]];
					m[i] = max(m[i],dp[j][k]);
				}
			}
		}
		cout << max(m[0],max(m[1],max(m[2],m[3]))) << endl;
	}
}

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

int map[256][256];
int w;
int dx[8]={0,0,1,-1,-1,-1,1,1};
int dy[8]={1,-1,0,0,-1,1,-1,1};

int dfs(int x,int y){
	int res=0;
	for(int i=0;i<8;i++){
		int re2=0;
		int cx=x,cy=y;
		while(map[cx][cy]==1 && cx>=0 && cx<w && cy>=0 && cy<w){
			re2++;
			cx+=dx[i];
			cy+=dy[i];
		}
		res=max(res,re2);
	}
	return res;
}

int main(void){
	while(1){
		scanf("%d",&w);
		if(w==0)break;
		memset(map,0,sizeof(map));
		for(int i=0;i<w;i++){
			string str;
			cin >> str;
			for(int j=0;j<w;j++){
				map[j][i]=str[j]-'0';
			}
		}
		int ans=0;
		for(int i=0;i<w;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]==1)ans=max(ans,dfs(i,j));
			}
		}
		printf("%d\n",ans);
	}
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
char f[300][300];
bool used[300][300];
int n;
int ans;
int dx[4]={1,0,1,1};
int dy[4]={0,1,-1,1};
void dfs(int x,int y,int d,int k)
{
	if(x<0||x>=n||y<0||y>=n)return;
	if(used[x][y])return;
	if(f[x][y]=='0')return;
	ans=max(ans,d);
	dfs(x+dx[k],y+dy[k],d+1,k);
	return;
}
void solve(int k)
{
	memset(used,false,sizeof(used));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			dfs(i,j,1,k);
		}
	}
	return ;
}
int main()
{
	while(1)
	{
		ans=0;
		cin >> n;
		if(n==0)break;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				cin >> f[i][j];
			}
		}
		for(int i=0;i<4;i++)solve(i);
		cout << ans << endl;
	}
	return 0;
}