In this problem you have to find the number of angle you turn the lock to unlock... First there is must three turn so we can count first 3*360 angle then you have to find the minimum distance between the point and have to count the angle multiplying digit by 9.
try this after trying if you don't understand then only see the code.otherwise you can't improve yourself in programming.
#include<stdio.h>
int main()
{
int a,b,c,d,t1,t2,t3,angle;
while(scanf("%d %d %d %d",&a,&b,&c,&d))
{
if(a==0&&b==0&&c==0&&d==0)
break;
if(a<b)
t1=40-(b-a);
else
t1=a-b;
if(b>c)
t2=40-(b-c);
else
t2=c-b;
if(c<d)
t3=40-(d-c);
else
t3=c-d;
angle=360*3+(t1+t2+t3)*9;
printf("%d\n",angle);
}
return 0;
}
try this after trying if you don't understand then only see the code.otherwise you can't improve yourself in programming.
#include<stdio.h>
int main()
{
int a,b,c,d,t1,t2,t3,angle;
while(scanf("%d %d %d %d",&a,&b,&c,&d))
{
if(a==0&&b==0&&c==0&&d==0)
break;
if(a<b)
t1=40-(b-a);
else
t1=a-b;
if(b>c)
t2=40-(b-c);
else
t2=c-b;
if(c<d)
t3=40-(d-c);
else
t3=c-d;
angle=360*3+(t1+t2+t3)*9;
printf("%d\n",angle);
}
return 0;
}
No comments:
Post a Comment