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 <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 <cstring>
using namespace std;
int n;
char t[256][256];
int d[4][2] = {
	{-1, 0},
	{-1. -1},
	{0, -1},
	{1, -1},
};
int main() {
	while (cin >> n, n) {
		for (int i = 0; i < n; i++) {
			cin >> t[i];
		}
		int result = 0;
		for (int i = 0; i < 4; i++) {
			int res[256][256];
			memset(res, 0, sizeof(res));
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					int preX = k + d[i][0];
					int preY = j + d[i][1];
					if ((preX < 0 || preY < 0) && t[j][k] == '1') {
						res[j][k] = 1;
					}
					else {
						if (t[j][k] == '1') {
							res[j][k] = res[preY][preX] + 1;
						}
					}
					result = max(result, res[j][k]);
					//cout << ' ' << res[j][k];
				}
				//cout << endl;
			}
		}
		cout << result << endl;
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int mt[256][256];
int n;

int f(int i,int j){
	int k;
	int max=0;
	int c;
	c=0;
	for(k=0;k+j<n;k++){
		if(mt[i][k+j])c++;
		else break;
	}
	chmax(max,c);
	c=0;
	for(k=0;k+i<n;k++){
		if(mt[k+i][j])c++;
		else break;
	}
	chmax(max,c);
	c=0;
	for(k=0;k+i<n&&k+j<n;k++){
		if(mt[k+i][k+j])c++;
		else break;
	}
	chmax(max,c);
	c=0;
	for(k=0;k+i<n&&0<=j-k;k++){
		if(mt[k+i][j-k])c++;
		else break;
	}
	chmax(max,c);
	return max;
}

int main() {
	while(n=in()){
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%1d",&mt[i][j]);
			}
		}
/*
for(i=0;i<n;i++){
	for(j=0;j<n;j++){
		cout<<mt[i][j];
	}
	cout<<endl;
}
*/
		int max=0;
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				chmax(max,f(i,j));
			}
		}
		cout<<max<<endl;
	}
	return 0;
}

C++: #include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<iostream>
using namespace std;
typedef vector<int> vi;
string board[265];

int main()
{
  int n;
  while(cin >> n && n)
    {
      int ans=-1;
      int wchain=0;
      int hchain=0;
      int schain=0;
      for(int i=0;i<n;i++)
	{
	  cin >> board[i];
	}
      for(int i=0;i<n;i++)
	{
	  wchain=0;
	  for(int j=0;j<n;j++)
	    {
	      if(board[i][j]=='1')
		{
		  wchain++;
		}
	      else
		{
		  ans=max(ans,wchain);
		  wchain=0;
		}
	    }
	  ans=max(ans,wchain);
	}
      for(int i=0;i<n;i++)
	{
	  hchain=0;
	  for(int j=0;j<n;j++)
	    {
	      if(board[j][i]=='1')
		{
		  hchain++;
		}
	      else
		{
		  ans=max(ans,hchain);
		  hchain=0;
		}
	    }
	   ans=max(ans,wchain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=i,w=0;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h-1)>=0 && (w+1)<n)
	    {
	      h--;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	   ans=max(ans,schain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=n-1,w=i;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h-1)>=0 && (w+1)<n)
	    {
	      h--;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}


       for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=i,w=0;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h+1)<n && (w+1)<n)
	    {
	      h++;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}
      for(int i=0;i<n;i++)
	{
	  schain=0;
	  int h=0,w=i;
	  if(board[h][w]=='1')
	    {
	      schain++;
	    }
	  else
	    {
	      ans=max(ans,schain);
	      schain=0;
	    }
	  while((h+1)<n && (w+1)<n)
	    {
	      h++;
	      w++;
	      if(board[h][w]=='1')
		{
		  schain++;
		}
	      else
		{
		  ans=max(ans,schain);
		  schain=0;
		}
	    }
	  ans=max(ans,schain);
	}
      cout << ans << endl;
    }
  return 0;
}