Pages

Sunday 9 September 2012

UVA - 579 - ClockHands

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        InputStreamReader isr=new InputStreamReader(System.in);
        BufferedReader br=new BufferedReader(isr);
        while(true){
            String m=br.readLine();
            String[] str=m.split(":");
            int x=Integer.parseInt(str[0]);
            int y=Integer.parseInt(str[1]);
            if(x==0 && y==0)
                break;
            if(x>11)
                x-=12;
            float secondangle=(float) (y*6);
            float firstangle=(float) (x*(30)+30*(y/60.0));
            float ans=Math.abs(firstangle-secondangle);
            ans=Math.min(360-ans,ans);
            System.out.printf("%.3f\n",ans);
        }
    }
}

No comments:

Post a Comment