fork download
  1. import java.util.*;
  2.  
  3. public class Main
  4. {
  5. public static void main(String[] args) {
  6. Scanner sc = new Scanner(System.in);
  7. int t = sc.nextInt();
  8. sc.nextLine();
  9. while (t-- > 0) {
  10. solve(sc);
  11. }
  12. sc.close();
  13. }
  14.  
  15. public static void solve(Scanner sc)
  16. {
  17. String a=sc.nextLine();
  18. // char q=a.charAt(0);
  19. String ap="";
  20. // int d=(int)q;
  21. // d=d-48;
  22. // if(d==0)
  23. // ap="AM";
  24. // else
  25. // ap="PM";
  26. String min=a.substring(2,5);
  27. String hours;
  28. int num;
  29. if(a.charAt(0)!='0')
  30. {
  31. hours=a.substring(0,2);
  32. num=Integer.parseInt(hours);
  33. }
  34. else
  35. {
  36. hours=a.substring(1,2);
  37. num=Integer.parseInt(hours);
  38. }
  39. if(num<12 && num>=0)
  40. {
  41. // System.out.println(num);
  42. ap="AM";
  43. }
  44. else
  45. ap="PM";
  46.  
  47.  
  48. if(ap=="AM")
  49. {
  50. if(a.charAt(0)=='0'&& a.charAt(1)=='0')
  51. System.out.println(12+min+ap);
  52. else
  53. System.out.println(num+""+min+ap);
  54.  
  55. }
  56. else
  57. {
  58. // String hours=a.substring(0,2);
  59. // int num=Integer.parseInt(hours);
  60. if(num!=12)
  61. {
  62. int k=num-12;
  63. System.out.println(k+""+min+ap);
  64. }
  65. else
  66. System.out.println(num+""+min+ap);
  67.  
  68. }
  69. }
  70.  
  71. }
  72.  
  73.  
Success #stdin #stdout 0.2s 61048KB
stdin
11
09:41
18:06
12:14
00:59
00:00
14:34
01:01
19:07
11:59
12:00
21:37
stdout
9:41AM
6:06PM
12:14PM
12:59AM
12:00AM
2:34PM
1:01AM
7:07PM
11:59AM
12:00PM
9:37PM