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 a,b,c,d,e,f; scanf("%d", &c); for(d=1; d<=c; d++) { scanf("%d%d", &a, &b); if(a<=b) e=b*4+19; else e=(2*a-b)*4 +19; printf("Case %d: %d\n", d,e); } return 0; }
why do we have to give the condition e=(2*a-b)*4+19
ReplyDeleteI m also not understand this logic
ReplyDelete'a' is your position
Delete'b' is lift position
'2*a' is twice your position or ground to you & you to ground
'2*a-b' is total floor left need to travel
'*4' is time for each floor
'19' is total time for open+entry+close++open+exit.