Thứ Sáu, 13 tháng 5, 2022

BANCO C++

#include <bits/stdc++.h>
using namespace std;
char a[100][100],res=0;
int h[100][100],c[100][100],ch1[100][100],ch2[100][100];
void nhap()
{
    for(int i=1;i<=8;i++)
        for(int j=1;j<=8;j++)
            cin>>a[i][j];
}

void giai()
{
    for(int i=1;i<=8;i++)
        for(int j=1;j<=8;j++)
        {
            if(a[i][j]=='1')
            {
                h[i][j]=h[i][j-1]+1;
                c[i][j]=c[i-1][j]+1;
                ch1[i][j]=ch1[i-1][j-1]+1;
                ch2[i][j]=ch2[i-1][j+1]+1;
            }
            else
            {
                h[i][j]=0;
                c[i][j]=0;
                ch1[i][j]=0;
                ch2[i][j]=0;
            }
        }
    int maxx=0;
    for(int i=1;i<=8;i++)
        for(int j=1;j<=8;j++)
        {
            if(h[i][j]>maxx)  maxx=h[i][j];
            if(c[i][j]>maxx)  maxx=c[i][j];
            if(ch1[i][j]>maxx)  maxx=ch1[i][j];
            if(ch2[i][j]>maxx)  maxx=ch2[i][j];
        }

    cout<<maxx;

}
int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0); cin.tie(0);
    freopen("banco.inp","r",stdin);
    freopen("banco.out","w",stdout);
    nhap();
    giai();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.