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>
using namespace std;

int main(){
	int n;
	while(cin >> n){
		if(!n){
			break;
		}
		bool field[255][255];
		int  count = 0;
		for(int i=0;i<n;i++){
			string f;
			cin >> f;
			for(int j=0;j<n;j++){
				if(f[j] == '1')
					field[i][j] = 1;
				else
					field[i][j] = 0;
			}
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(field[i][j] == 1){
					int cnt=0;
					for(int k=0;k<n;k++){
						if((field[i+k][j] == 1) && (i+k < n)){
							cnt++;
						}
						else{		
							break;
						}
					}
					count = max(count,cnt);
					cnt = 0;
					for(int k=0;k<n;k++){
						if(field[i][j+k] == 1 && j+k < n){
							cnt++;
						}
						else
							break;
					}
					count = max(count,cnt);
					cnt = 0;
					for(int k=0;k<n;k++){
						if(field[i+k][j+k] == 1 && i+k < n && j+k < n)
							cnt++;
						else
							break;
					}
					count = max(count,cnt);
					cnt = 0;
					for(int k=0;k<n;k++){
						if(field[i+k][j-k] == 1 && i+k < n && j-k >= 0){
							cnt++;
						}
						else
							break;
					}
					count = max(count,cnt);
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,a) for(int i = 0; i < (a); i++)
bool prime[10002];
int field[256][256];
int dx[] = {1,1,0}, dy[] = {-1,0,1};
int n;
int func(int x, int y, int k) {
	int cnt = 0;
	while(1) {
		if(x < 0 || x >= n || y < 0 || y >= n) break;
		if(field[y][x] == 0) break;
		x += dx[k], y+= dy[k];
		cnt += 1;
	}
	return cnt;
}
int main() {
	while(cin >> n,n) {
		rep(i,n){
			string str;
			cin >> str;
			rep(j, str.size()){
				field[i][j] = str[j] - '0';
			}
		}
		int ans = 0;
		rep(i, n) {
			rep(j, n) {
				if(field[i][j] == 0) continue;
				rep(k, 3) {
					ans = max(func(j,i,k),ans);
				}
			}
		}
		cout << ans << endl;
	}

	return 0;
}

C++: #include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
	int n,i,j,c,max_c;
	while(scanf("%d",&n),n)
	{
		const int OFFSET = 256,MAX_I=OFFSET,MAX_J=OFFSET*3;
		char a[MAX_I][MAX_J] = {0};
		for(i=0;i<n;++i)
			scanf("%s",&a[i][OFFSET]);
		max_c = c =0;
		for(j=OFFSET;j<MAX_J;++j)
			for(c=0,i=0;i<MAX_I;++i)
				(a[i][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(i=0;i<MAX_I;++i)
			for(c=0,j=OFFSET;j<MAX_J;++j)
				(a[i][j]=='1') ? max_c=max(++c,max_c): c=0;
		for(j=0; j<MAX_J ; ++j)
			for(c=0,i=0; i<MAX_I; ++i)
				if(i+j<=MAX_J)
					(a[i][i+j]=='1') ? max_c=max(++c,max_c): c=0;
		for(j=0; j<MAX_J; ++j)
			for(c=0,i=0;i<MAX_I; ++i)
				if( j-i>=0)
					(a[i][j-i]=='1') ? max_c=max(++c,max_c): c=0;
		printf("%d\n",max_c);
	}
	return 0;
}

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

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 <vector>
#include <cstring>
#include <string>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	int n;
	string s[256];
	while(cin >> n && n)
	{
		rep(i,n)
		{
			cin >> s[i];
		}

		int len = 0;
		int ans = 0;

		rep(i,n)
		{
			bool flag = false;
			len = 0;
			rep(j,n)
			{
				if(s[i][j] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;	
				}
				else 
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}

		rep(i,n)
		{
			len = 0;
			bool flag = false;
			rep(j,n)
			{
				if(s[j][i] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;	
				}
				else 
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}

		rep(i,n)
		{
			bool flag =false;
			len = 0;
			rep(k,i+1)
			{
				if(s[k][i-k] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}
		/*   //under  */
		for(int i=n-1;i>=0;i--)
		{
			bool flag = false;
			len = 0;
			int cnt = n-1;
			for(int j=i;j<n;j++)
			{
				if(s[j][cnt] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt--;
			}
			ans = max(ans,len);
		}
		/*  \\up */
		rep(i,n)
		{
			bool flag = false;
			len = 0;
			int cnt = 0;
			REP(j,i,n)
			{
				if(s[cnt][j] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt++;
			}
			ans = max(ans,len);
		}
		/*   \\under */
		for(int i=n-1;i>=0;i--)
		{
			bool flag = false;
			len = 0;
			int cnt = 0;
			for(int j=i;j<n;j++)
			{
				if(s[j][cnt] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt++;
			}
			ans = max(ans,len);
		}
		
		cout << ans << endl;
	}
	return 0;
}