Saturday, 16 July 2016

Solution of URI 2140 :: Two Bills


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 N, M, net, i, cndtn;
    int bill[15] = {7, 12, 22, 52, 102, 15, 25, 55, 105, 30, 60, 110, 70, 120, 150};
    while(1)
    {
        scanf("%d%d", &N, &M);
        if(N==0 && M==0) break;
        net = M - N;
        for(i=0, cndtn = 0; i<15; i++)
        {
            if(bill[i] == net)
            {
                cndtn = 1;
                break;
            }
        }
        if(cndtn) printf("possible\n");
        else printf("impossible\n");
    }
    return 0;
}


4 comments:

  1. asallam alykom
    why in this problem using addition between two available bills on any based
    you deduce this thanks you in advance

    ReplyDelete
  2. Wouldn't be easier to create an array with the available bills?

    like:
    bills[] = {2,5,10,20,50,100};

    and then compare the change(net) with the sum of two bills ?

    like:
    for(i=0; i<6; ++i)
    for(j=0; j<6; ++j)
    if((bills[i] + bills[j]) == net)
    ans += 1;

    if(ans == 0)
    impossible
    else
    possible

    Just a suggestion. ;D

    ReplyDelete
  3. #include
    using namespace std;
    int main()
    {
    int a,b,c;
    while(1)
    {
    cin>>a>>b;
    c=187;
    if(a<1 && b<1)
    {
    return 0;
    }
    if((b-a)<187 && (b-a)>2)
    {
    cout<<"possible"<<endl;
    }
    else{
    cout<<"impossible"<<endl;
    }
    }
    return 0;
    }

    ReplyDelete

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