2011年2月18日金曜日

Aizu Online Judge 0135 Clock Short Hand and Long Hand

■0135 Clock Short Hand and Long Hand

時計の長針・短針の角度をそれぞれ360°に直すだけ.

  1. import java.util.*;  
  2. import java.lang.*;  
  3. import java.math.*;  
  4. import java.io.*;  
  5.   
  6. import static java.lang.Math.*;  
  7. import static java.util.Arrays.*;  
  8.   
  9. public class Main{  
  10.   
  11.  Scanner sc=new Scanner(System.in);  
  12.   
  13.  int INF=1<<28;  
  14.  double EPS=1e-9;  
  15.   
  16.  void run(){  
  17.   int n=sc.nextInt();  
  18.   sc.useDelimiter("(\\s)+|[:]");  
  19.   for(int i=0; i<n; i++){  
  20.    double h=sc.nextInt()*30;  
  21.    double m=sc.nextInt()*6;  
  22.    h+=m/12;  
  23.    double d=Math.abs(h-m);  
  24.    d=Math.min(d, 360-d);  
  25.    if(d+EPS<30){  
  26.     println("alert");  
  27.    }else if(d+EPS>=90&&d<=180+EPS){  
  28.     println("safe");  
  29.    }else{  
  30.     println("warning");  
  31.    }  
  32.   }  
  33.  }  
  34.   
  35.  void debug(Object... os){  
  36.   System.err.println(Arrays.deepToString(os));  
  37.  }  
  38.   
  39.  void print(String s){  
  40.   System.out.print(s);  
  41.  }  
  42.   
  43.  void println(String s){  
  44.   System.out.println(s);  
  45.  }  
  46.   
  47.  public static void main(String[] args){  
  48.   // System.setOut(new PrintStream(new BufferedOutputStream(System.out)));  
  49.   new Main().run();  
  50.  }  
  51. }  

0 件のコメント: