fork download
  1. import java.util.*;
  2.  
  3. class Main{
  4.  
  5. public static void main(String[] args){
  6. Scanner sc = new Scanner(System.in);
  7. int i, tc, m1=0, m2=0, d1=0, d2=0, y1=0, y2=0, age=0;
  8. String input, input2;
  9. String[] numbers, numbers2;
  10.  
  11. tc = sc.nextInt();
  12. sc.nextLine();
  13. for(i=1; i<=tc; i++){
  14. System.out.println();
  15. input = sc.nextLine();
  16. sc.nextLine();
  17. input2 = sc.nextLine();
  18.  
  19. if( input.isEmpty() || input2.isEmpty() ){
  20. System.out.format("Case #%d: Invalid birth date\n",i);
  21. }
  22.  
  23. else{
  24. numbers = input.split("/");
  25. numbers2 = input2.split("/");
  26.  
  27. if(numbers.length==3 && numbers2.length==3){
  28. d1 = Integer.parseInt(numbers[0]);
  29. m1 = Integer.parseInt(numbers[1]);
  30. y1 = Integer.parseInt(numbers[2]);
  31.  
  32. d2 = Integer.parseInt(numbers2[0]);
  33. m2 = Integer.parseInt(numbers2[1]);
  34. y2 = Integer.parseInt(numbers2[2]);
  35. }
  36.  
  37. if( y2>y1 || (y2==y1 && m2>m1) || (y2==y1 && m2==m1 && d2>d1) ){
  38. System.out.format("Case #%d: Invalid birth date\n", i);
  39. }
  40. else if( y1-y2 > 130 ){
  41. System.out.format("Case #%d: Check birth date\n",i);
  42. }
  43. else{
  44. age = y1-y2;
  45. if( m2>m1 || (m2==m1 && d2>d1) )
  46. age--;
  47. if(age<0)
  48. age = 0;
  49. System.out.format("Case #%d: %d\n", i, age);
  50. }
  51. }
  52. }
  53.  
  54.  
  55.  
  56. }
  57.  
  58. }
Success #stdin #stdout 0.1s 380736KB
stdin
4

01/01/2007
10/02/2007

09/06/2007
28/02/1871

12/11/2007
01/01/1984

28/02/2005
29/02/2004
stdout
Case #1: Invalid birth date

Case #2: Invalid birth date

Case #3: Invalid birth date

Case #4: Invalid birth date