fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. private static final int daysInMonth[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
  11.  
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. long start = System.currentTimeMillis();
  15. for (int i=0;i<1000000;i++) {
  16. for (int m=1;m<=12;m++){
  17. days1(m);
  18. }
  19. }
  20. long end = System.currentTimeMillis();
  21. System.out.println(end-start);
  22.  
  23. start = System.currentTimeMillis();
  24. for (int i=0;i<1000000;i++) {
  25. for (int m=1;m<=12;m++){
  26. days2(m);
  27. }
  28. }
  29. end = System.currentTimeMillis();
  30. System.out.println(end-start);
  31.  
  32. start = System.currentTimeMillis();
  33. for (int i=0;i<1000000;i++) {
  34. for (int m=1;m<=12;m++){
  35. days3(m);
  36. }
  37. }
  38. end = System.currentTimeMillis();
  39. System.out.println(end-start);
  40. }
  41.  
  42. public static int days1(int m) {
  43. return (0xEEFBB3>>(m-1)*2 & 0b11) + 28;
  44. }
  45.  
  46. public static int days2(int x) {
  47. return 28 + (x + (int)Math.floor(x/8)) % 2 + 2 % x + 2 * (int)Math.floor(1/x);
  48. }
  49.  
  50. public static int days3(int month) {
  51. return daysInMonth[month];
  52. }
  53. }
Success #stdin #stdout 1.32s 380160KB
stdin
Standard input is empty
stdout
20
1202
22