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 <vector>
#include <iomanip>

using namespace std;

int saiki(int y,int x,int dir,vector<vector<char> > &field,vector<vector<vector<int> > > &table,int count){
    if(table[y][x][dir] != -1) return count+table[y][x][dir];
    if(field[y][x] == '0') return count;
    int m;
    switch(dir){
    case 0:
        m= saiki(y+1,x,dir,field,table,count+1);
        break;
    case 1:
        m= saiki(y+1,x+1,dir,field,table,count+1);
        break;
    case 2:
        m= saiki(y,x+1,dir,field,table,count+1);
        break;
    case 3:
        m= saiki(y-1,x+1,dir,field,table,count+1);
        break;
    case 4:
        m= saiki(y-1,x,dir,field,table,count+1);
        break;
    case 5:
        m= saiki(y-1,x-1,dir,field,table,count+1);
        break;
    case 6:
        m= saiki(y,x-1,dir,field,table,count+1);
        break;
    case 7:
        m= saiki(y+1,x-1,dir,field,table,count+1);
        break;
    }
    table[y][x][dir] = m;
    return m;
}

int solve(vector<vector<char> > field){
    int n = field.size();
    //[y][x][dir]
    vector<vector<vector<int> > > v(n,vector<vector<int> >(n,vector<int>(8,-1)));

    for(int i=0;i<n;i++){
        for(int j=0;j<8;j++){
            v[i][0][j] = 0;
            v[i][n-1][j] = 0;
            v[0][i][j] = 0;
            v[n-1][i][j] = 0;
        }
    }
    int ret = 0;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            for(int k=0;k<8;k++){
                ret = max(saiki(i,j,k,field,v,0),ret);
            }
        }
    }
    return ret;
}

int main(){
    int n;
    while(cin >> n && n!= 0){
        vector<vector<char> > v(n+2,vector<char>(n+2,'0'));
        for(int i=1;i<n+1;i++){
            for(int j=1;j<n+1;j++){
                char c;
                cin >> c;
                if(c=='1')v[i][j] = '1';
            }
        }
        cout << solve(v) << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <cmath>

using namespace std;

int n;

const int MAX = 255;
int M[MAX][MAX];

int solve()
{
	int mval = 0;
	
	for(int i=0; i<n; i++)
	{
		int c = 0;
		for(int j=0; j<n; j++)
		{
			if(M[i][j]==1)
			{
				c++;
			}
			else
			{
				if(c > mval) mval =c;
				c = 0;
			}
		}
		
		if(c > mval)
		{
			mval = c;
		}
	}
	
	for(int i=0; i<n; i++)
	{
		int c = 0;
		for(int j=0; j<n; j++)
		{
			if(M[j][i]==1)
			{
				c++;
			}
			else
			{
				if(c > mval) mval =c;
				c = 0;
			}
		}
		
		if(c > mval)
		{
			mval = c;
		}
	}
	
	for(int i=0; i<n; i++)
	{
		int c = 0;
		for(int j=0; j<=i; j++)
		{
			if(M[i-j][j]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		c = 0;
		for(int j=0; j<n-i; j++)
		{
			if(M[i+j][j]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		c = 0;
		for(int j=0; j<=i; j++)
		{
			if(M[i-j][n-j-1]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		c = 0;
		for(int j=0; j<n-i; j++)
		{
			if(M[i+j][n-j-1]==1) c++;
			else
			{
				mval = max(c, mval);
				c = 0;
			}
		}
		mval = max(c, mval);
		
		
	}
	
	return mval;
}

int main(int argc, char** argv)
{
	string tmp;
	char c[1];
	
	while(cin >> n, n)
	{
		for(int i=0; i<n; i++)
		{
			cin >> tmp;
			for(int j=0; j<n; j++)
			{
				memcpy(c, &tmp[j], sizeof(char));
				M[i][j] = atoi(c);
			}
		}
		
		cout << solve() << endl;;
	}
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
char field[255][255];

int main(){
  int n;
  while(cin >> n && n){
    rep(i, n)rep(j, n) cin >> field[i][j];
    int res = 0;
    int cnt = 0;
    // yoko
    rep(i, n){
      cnt = 0;
      rep(j, n){
	if(field[i][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //tate
    rep(i, n){
      cnt = 0;
      rep(j, n){
	if(field[j][i] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    
    rep(i, n){
      cnt = 0;
      rep(j, i+1){
	if(field[i-j][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //naname
    rep(i, n){
      cnt = 0;
      rep(j, n-i){
	if(field[n-i-j-1][i+j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    //naname  
    rep(i, n){
      cnt = 0;
      rep(j, n - i){
	if(field[i+j][j] == '1') cnt++;
	else cnt = 0;
      }
      res = max(res, cnt);
    }
    rep(i, n){
      cnt = 0;
      rep(j, n - i){
	if(field[j][i+j] == '1') cnt++;
	else cnt = 0;
      }
      res = max(res, cnt);
    }
    cout << res << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int n;
string str[4][255];

int migi(int y,int x) {
  int count = 0;

  for(int i=x;i<n;i++){
    if(str[0][y][i] == '1') {
      count++;
      str[0][y][i] = '0';
    }
    else break;
  }
  return count;

}

int sita(int y,int x) {
  int count = 0;
  for(int i=y;i<n;i++) {
    if(str[1][i][x] == '1') {
      count++;
      str[1][i][x] = '0';
    }
    else break;
  }

  return count;
}

int migisita(int y,int x) {
  int count = 0;
  int i=0;
  while(1) {
    if(y+i == n || x+i == n) break;

    if(str[2][y+i][x+i] == '1'){
      str[2][y+i][x+i] = '0';
      count++;
    }
    else break;
    i++;
  }
  return count;
}

int hidarisita(int y,int x) {
 int count = 0;
  int i=0;
  while(1) {
    if(y+i == n || x-i == -1) break;

    if(str[3][y+i][x-i] == '1'){
      str[3][y+i][x-i] = '0';
      count++;
    }
    else break;
    i++;
  }
  return count;
}


int main(){
  while(1) {
  cin >> n;
  if(n == 0) break;

  for(int i=0;i<n;i++) {
    cin >> str[0][i];
    str[1][i] = str[2][i] = str[3][i] = str[0][i];
  }

  int ans = 0,t;
    for(int i=0;i<n;i++) {
      for(int j=0;j<n;j++) {
	if(str[0][i][j] == '1') ans = max(ans,migi(i,j));
	if(str[1][i][j] == '1') ans = max(ans,sita(i,j));
	if(str[2][i][j] == '1') ans = max(ans,migisita(i,j));
	if(str[3][i][j] == '1') ans = max(ans,hidarisita(i,j));
      }
    }

    cout << ans << endl;

  }

  return 0;
}

C++: #include<iostream>
#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);

	  j += d-1;
	}
      }
    }

    cout << ans << endl;
  }
}