Friday, April 24, 2015

UVa - 579 - Clock Hands


  1. #include <iostream>
  2. #include <cstdio>
  3. #include <iomanip>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. int main(){
  8.     double h, m, ht, mt, angle, div, te1, te2, mp1, temp1, temp2;
  9.     while(scanf("%lf:%lf"&h, &m) == 2){
  10.         if(== 0 && h == m)break;
  11.         div = (5*m)/60;
  12.         ht = (h*5) + div; mt = m;
  13.         te1 = max(ht, mt);
  14.         te2 = min(ht, mt);
  15.         mp1 = 60 - te1;
  16.         temp1 = (mp1 + te2)*6;
  17.         temp2 = (te1 - te2)*6;
  18.         if(temp1 < 0)temp1 *= -1;
  19.         if(temp2 < 0)temp2 *= -1;
  20.         angle = min(temp1, temp2);
  21.         while(angle > 180)angle -= 180;
  22.         cout << fixed << setprecision(3) << angle << endl;
  23.     }
  24.     return 0;
  25. }

No comments:

Post a Comment