Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Date: 2014.10.09
- * @author LinChuWen
- * UVa Online Judge Problem #579 - Clock Hands
- * Description: The output displays the smallest positive angle in degrees between the hands for each time.
- * The answer should between 0 degrees and 180 degrees for all input times.
- * Display each angle on a line by itself in the same order as the input.
- * The output should be rounded to the nearest 1/1000.
- */
- import java.util.*;
- public class UVa_579 {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String time,str_h,str_m;
- int h,m;
- int length;
- float dh,dm,answer;
- while(input.hasNext()){
- time = input.nextLine();
- length = time.length();
- str_m = time.substring(length-2, length);
- str_h = time.substring(0, length-3);
- m = Integer.parseInt(str_m);
- h = Integer.parseInt(str_h);
- if(h==0 && m==0)
- break;
- dh=(float) (h*30+m*0.5);
- dm=(float) (m*6.0);
- answer=dh-dm;
- if(answer<0)
- answer=-answer;
- if(answer>180)
- answer=360-answer;
- System.out.printf("%.3f\n",answer);
- } //big while end
- input.close();
- } //main end
- } //class end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement