Saturday, January 14, 2017

UVa-579-Clock Hands

Problem link: Clock Hands

For detail information click hare 

Source code in C++:

#include<bits/stdc++.h>
#define file freopen("in.txt","rt",stdin)
int main()
{
   // file;
    int c=0,a;
    float h,m,H,d1,d2,ans;
    char str[10];
    while(gets(str))
    {
        a = strcmp(str,"0:00");
        if(a==0)
            break;
        if(strlen(str)==4)
        {
            h = str[0]-48;
            m = (str[2]-48)*10+(str[3]-48);

            H = h*60+m;
            d1 = H*0.5;
            d2 = m*6;
            ans= fabs(d1-d2);
            if(ans>180)
                ans-=360;
            printf("%.3f\n",fabs(ans));

        }
        else
        {
            h = (str[0]-48)*10+(str[1]-48);
            m = (str[3]-48)*10+(str[4]-48);

             H = h*60+m;
            d1 = H*0.5;
            d2 = m*6;
            ans= fabs(d1-d2);
            if(ans>180)
                ans-=360;
            printf("%.3f\n",fabs(ans));
        }
    }
    return 0;
}
 

No comments:

Post a Comment