TABLA DE SAH C++

Configurare noua (How To)

Situatie

Creare tabla de sah in C++

Solutie

date.in:
4
4 4
1 0 0 1
0 0 0 1
1 0 1 0
0 0 1 1
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin(“date.in”);
int main()
{
typedef struct punct
{
int l,c;
};
punct x;
int n,i,j,a[100][100];
int t=0;
fin>>n;
fin>>x.l>>x.c;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
fin>>a[i][j];
i=x.l-1;
j=x.c-1;
while(i>=1 && j>=1)
{
if(a[i][j]==1) t++;
i–;
j–;
}
i=x.l-1;
j=x.c+1;
while(i>=1 && j<=n)
{
if(a[i][j]==1) t++;
i–;
j++;
}
i=x.l+1;
j=x.c-1;
while(i<=n && j>=1)
{
if(a[i][j]==1) t++;
i++;
j–;
}
i=x.l+1;
j=x.c+1;
while(i<=n && j<=n)
{
if(a[i][j]==1) t++;
i++;
j++;
}
if(a[x.l][x.c]==1)
t++;
if(t)
cout<<t<<‘ ‘;
else cout<<“Nu sunt obstacole”;
return 0;
}

Tip solutie

Permanent

Voteaza

(13 din 28 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?