Advertisement
Go-Ice

UVa [579 - Clock Hands] by Go-Ice

Oct 9th, 2014
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. /*
  2.     Author: LinChuWen
  3.     Date: 2014/10/05
  4.     UVa Online Judge Problem #579 - Clock Hands
  5.     Description: The output displays the smallest positive angle in degrees between the hands for each time.
  6.              The answer should between 0 degrees and 180 degrees for all input times.
  7.              Display each angle on a line by itself in the same order as the input.
  8.              The output should be rounded to the nearest 1/1000.
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. int main(){
  14.     int h,m;
  15.     float dh,dm,answer;
  16.    
  17.     while(scanf("%d:%d",&h,&m)==2){
  18.         if(h==0 && m==0)
  19.             break;
  20.            
  21.         dh=h*30+m*0.5;
  22.         dm=m*6;
  23.        
  24.         answer=dh-dm;
  25.         if(answer<0)
  26.             answer=-answer;
  27.         if(answer>180)
  28.             answer=360-answer;
  29.        
  30.         printf("%.3f\n",answer);
  31.     }
  32.    
  33.     system("PAUSE");
  34.     return 0;
  35. } /* main end */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement