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; }
asallam alykom
ReplyDeletewhy in this problem using addition between two available bills on any based
you deduce this thanks you in advance
or this trick in this problem
DeleteWouldn't be easier to create an array with the available bills?
ReplyDeletelike:
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
#include
ReplyDeleteusing 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;
}