Main.java 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package CSP.temp.A1;
  2. import java.util.Scanner;
  3. /**
  4. * @Projectname: LeetCode
  5. * @Filename: CSP.temp.A1.CSP.temp.A2.CSP.temp.A3.CSP.temp.A4.CSP.temp.A5.Main
  6. * @Author: 杨逸
  7. * @Data:2023/9/2 13:27
  8. * @Description: U189818 时间间隔
  9. */
  10. public class Main {
  11. private final static Scanner input = new Scanner(System.in);
  12. private static int h1;
  13. private static int m1;
  14. private static int s1;
  15. private static int h2;
  16. private static int m2;
  17. private static int s2;
  18. public static void main(String[] args) {
  19. h1 = input.nextInt();
  20. m1 = input.nextInt();
  21. s1 = input.nextInt();
  22. h2 = input.nextInt();
  23. m2 = input.nextInt();
  24. s2 = input.nextInt();
  25. int result = 0;
  26. //秒差
  27. if (s2 >= s1){
  28. result +=s2-s1;
  29. }else{
  30. //借位
  31. result += s2-s1+60;
  32. if (m2>0){
  33. m2--;
  34. }else{
  35. h2--;
  36. m2 += 60;
  37. m2 --;
  38. }
  39. }
  40. //分钟差
  41. if (m2 >=m1){
  42. result += (m2-m1)*60;
  43. }else{
  44. //借位
  45. result += (m2-m1+60)*60;
  46. h2--;
  47. }
  48. //小时差
  49. result += (h2-h1)*3600;
  50. System.out.println(result);
  51. }
  52. }