Thursday, 14 January 2016

Solution of URI 1961 :: Jumping Frog


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 p, q, cnt=0, i, dif;
    scanf("%d%d", &p, &q);
    int jump[q];
    for(i=0; i<q; i++)
        scanf("%d",  &jump[i]);
    for(i=1; i<q; i++)
    {
        if(jump[i]>jump[i-1])
         dif = (jump[i] - jump[i-1]);
        else
         dif = (jump[i-1] - jump[i]);
        if(dif<=p)
            cnt++;
    }
    if(cnt== q-1)
        printf("YOU WIN\n");
    else
        printf("GAME OVER\n");
    return 0;
}

2 comments:

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