https://codeforces.com/problemset/problem/275/A

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    int a[3][3];
    int b[3][3]={0};
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            b[i-1][j]+=a[i][j];
            b[i+1][j]+=a[i][j];
            b[i][j+1]+=a[i][j];
            b[i][j]+=a[i][j];
            b[i][j-1]+=a[i][j];
        }
    }
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(b[i][j]%2==0)
            {
                cout<<"1";
            }else{
                cout<<"0";
            }
        }
        cout<<"\n";
    }

}

only the sample case 1 is running can u tell me the problem with my code please?
https://codeforces.com/problemset/problem/275/A

There are many problems with your code.
One main problem is negative array indexing.

1 Like

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n=3;
int a[3][3],b[3][3];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++){
cin>>a[i][j];
b[i][j]=1;
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(a[i][j]%2==0)
{}
else
{
if(b[i][j]==1) b[i][j]=0;
else b[i][j]=1;
if(i+1<n){
if(b[i+1][j]==1) b[i+1][j]=0;
else b[i+1][j]=1;
}
if(j+1<n){
if(b[i][j+1]==1) b[i][j+1]=0;
else b[i][j+1]=1;
}
if(j-1>=0){
if(b[i][j-1]==1) b[i][j-1]=0;
else b[i][j-1]=1;
}
if(i-1>=0){
if(b[i-1][j]==1) b[i-1][j]=0;
else b[i-1][j]=1;
}
}
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
cout<<b[i][j];
cout<<endl;
}
}

1 Like