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>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<string>in(n);
  rep(i,n)cin>>in[i];
  int out=0;
  rep(i,n){//横
    int sum=0;
    bool h=false;
    rep(j,n){
      if(in[i][j]=='1'){
	if(h)sum++;
	else {
	  h=true;
	  sum++;
	}
	out=max(sum,out);
      }else{
	h=false;
	sum=0;
      }
    }
  }
  rep(j,n){//縦
    int sum=0;
    bool h=false;
    rep(i,n){
      if(in[i][j]=='1'){
	if(h)sum++;
	else {
	  h=true;
	  sum++;
	}
	out=max(sum,out);
      }else{
	h=false;
	sum=0;
      }
    }
  }
  rep(i,n){//右肩斜め
    int k=i;
    int sum=0;
    bool h=false;
    rep(j,n){
      if(k<0)break;
      if(in[k][j]=='1'){
	if(h)sum++;
	else {
	  h=true;
	  sum++;
	}
	out=max(sum,out);
      }else{
	h=false;
	sum=0;
      }
      k--;
    }
  }
  rep(j,n){
    int k=j;
    int sum=0;
    bool h=false;
    for(int i=n-1;i>=0;i--){
      if(k<0)break;
      if(in[i][k]=='1'){
	if(h)sum++;
	else {
	  h=true;
	  sum++;
	}
	out=max(sum,out);
      }else{
	h=false;
	sum=0;
      }
      k--;
    }
  }
  rep(i,n){//左肩斜め
    int k=i;
    int sum=0;
    bool h=false;
    rep(j,n){
      if(k>=n)break;
      if(in[k][j]=='1'){
	if(h)sum++;
	else {
	  h=true;
	  sum++;
	}
	out=max(sum,out);
      }else{
	h=false;
	sum=0;
      }
      k++;
    }
  }
  rep(j,n){
    int k=j;
    int sum=0;
    bool h=false;
    for(int i=n-1;i>=0;i--){
      if(k<0)break;
      if(in[i][k]=='1'){
	if(h)sum++;
	else {
	  h=true;
	  sum++;
	}
	out=max(sum,out);
      }else{
	h=false;
	sum=0;
      }
      k++;
    }
  }



  cout<<out<<endl;
}

C++: #include<iostream>

using namespace std;

const int MAX = 257;

char data[MAX][MAX];
int num[4][MAX][MAX];
int in;

int solve(){
  for(int i = 1; i <= in; i++){
    for(int j = 1; j <= in; j++){
      if(data[i][j] == '1'){
	num[0][i][j] = num[0][i-1][j]+1;
	num[1][i][j] = num[1][i][j-1]+1;
	num[2][i][j] = num[2][i-1][j-1]+1;
	num[3][i][j] = num[3][i-1][j+1]+1;
      }
    }
  }
  int m = 0;
  for(int i = 0; i < 4; i++)
    for(int j = 1; j <= in; j++)
      for(int k = 1; k <= in; k++) m = max(m,num[i][j][k]);
  return m;
}

void init(){
  for(int i = 0; i < MAX; i++){
    fill(num[0][i],num[0][i]+MAX,0);
    fill(num[1][i],num[1][i]+MAX,0);
    fill(num[2][i],num[2][i]+MAX,0);
    fill(num[3][i],num[3][i]+MAX,0);
  }
}
int main(){

  while(cin >> in && in){
    init();
    for(int i = 1; i <= in; i++)
      for(int j = 1; j <= in; j++) cin >> data[i][j];

    cout << solve() << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

vector<int>primes;

const int adx[] = { 1,1,1,0,-1,-1,-1,0 };
const int ady[] = { 1,0,-1,-1,-1,0,1,1 };

int add(const int base, const int plus) {
	if (plus) {
		return base + 1;
	}
	else {
		return 0;
	}
}
vector<vector<vector<int>>>get_cumulative_sum(const vector<vector<int>>&field) {
	const int H = field.size();
	const int W = field[0].size();
	//0 :?????????1:??????2:?????????3:??? 4:?????????5:??? 6:?????? 7:???
	vector<vector<vector<int>>>sums(H, vector<vector<int>>(W, vector<int>(8)));
	for (int ny = 0; ny <H; ++ny) {
		for (int nx = 0; nx <W; ++nx) {
			for (int k = 0; k < 2; ++k) {
				int py = ny - ady[k];
				int px = nx - adx[k];
				if (!(px >= 0 && px <W && py >= 0 && py <H))continue;

				sums[ny][nx][k] = add(sums[py][px][k], field[ny][nx]);

			}
		}
	}
	for (int ny = H-1; ny >= 0; --ny) {
		for (int nx = 0; nx <W; ++nx) {
			for (int k = 2; k < 4; ++k) {
				int py = ny - ady[k];
				int px = nx - adx[k];
				if (!(px >= 0 && px <W && py >= 0 && py <H))continue;

				sums[ny][nx][k] = add(sums[py][px][k], field[ny][nx]);

			}
		}
	}
	for (int ny = H-1; ny >= 0; --ny) {
		for (int nx =W-1; nx >= 0; --nx) {
			for (int k = 4; k < 6; ++k) {
				int py = ny - ady[k];
				int px = nx - adx[k];
				if (!(px >= 0 && px <W && py >= 0 && py <H))continue;

				sums[ny][nx][k] = add(sums[py][px][k], field[ny][nx]);

			}
		}
	}
	for (int ny = 0; ny <H; ++ny) {
		for (int nx = W-1; nx >= 0; --nx) {
			for (int k = 6; k < 8; ++k) {
				int py = ny - ady[k];
				int px = nx - adx[k];
				if (!(px >= 0 && px <W && py >= 0 && py <H))continue;

				sums[ny][nx][k] = add(sums[py][px][k], field[ny][nx]);

			}
		}
	}
	return sums;
}

int main() {
	while (1) {

		int N; cin >> N;
		if (!N)break;
		vector<vector<int>>field(N+2, vector<int>(N+2));
		for (int i = 0; i < N; ++i) {
			string st; cin >> st;
			for (int j = 0;  j < N; ++j) {
				field[i+1][j+1] = st[j] - '0';
			}
		}
		auto vs(get_cumulative_sum(field));
		int ans = 0;
		for (auto aa : vs) {
			for (auto a : aa) {
				for (auto g : a) {
					ans = max(ans, g);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

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;
    rep(i, n){
      cnt = 0;
      rep(j, n){
	if(field[i][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    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);
      }
    }
    rep(i, n){
      cnt = 0;
      rep(j, n-i){
	if(field[n-i-j-1][j] == '1') cnt++;
	else cnt = 0;
	res = max(res, cnt);
      }
    }
    cout << res << endl;
  }
  return 0;
}