Tuesday, 30 August 2016

Solution of URI 2163 :: The Force Awakens


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim.**/

#include <stdio.h>
int main()
{
    int rw, clm, i, j, cndtn = 0, n = 0, m = 0;
    scanf("%d%d", &rw, &clm);
    int ara[rw][clm];
    for(i=0; i<rw; i++)
        for(j=0; j<clm; j++)
            scanf("%d", &ara[i][j]);

    for(i=1; i<rw-1; i++)
    {
        for(j=1; j<clm-1; j++)
        {
            if(ara[i][j]==42)
                if(ara[i-1][j-1]==7 && ara[i-1][j]==7 && ara[i-1][j+1]==7)
                    if(ara[i][j-1]==7 && ara[i][j+1]==7)
                        if(ara[i+1][j-1]==7 && ara[i+1][j]==7 && ara[i+1][j+1]==7)
                        {
                            cndtn = 1;
                            n = i+1;
                            m = j+1;
                        }
        }
    }
    printf("%d %d\n", n, m);
    return 0;
}

2 comments:

  1. cndtn = 1;

    why this statement..

    ReplyDelete
  2. int n,m,i,j,a,b,c=0,p=0,q=0;
    cin>>n>>m;
    int ara[n][m];
    for(a=1;a<=n;a++)
    {
    for(b=1;b<=m;b++)
    cin>>ara[a][b];
    }
    for(i=2;i<=n-1;i++)
    {
    for(j=2;j<=m-1;j++)
    {
    if(ara[i][j]==42)
    {
    if(ara[i-1][j-1]==7&&ara[i-1][j]==7&&ara[i-1][j+1]==7)
    {
    if(ara[i][j+1]==7&&ara[i][j-1]==7)
    {
    if(ara[i+1][j-1]==7&&ara[i+1][j]==7&&ara[i+1][j+1]==7)
    p=i;
    q=j;
    }
    }

    }

    }
    }
    cout<<p<<" "<<q<<endl;
    why i got run time error??
    would you please help me...
    thanks in advance...

    ReplyDelete

Note: only a member of this blog may post a comment.