IDENTIFICATION DIVISION.
PROGRAM-ID. 168C.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC X(100).
01 A          PIC 9(04).
01 B          PIC 9(04).
01 H          PIC 9(02).
01 M          PIC 9(02).
01 W          PIC 9(08)       COMP.
01 AK         PIC 9(04)V9     COMP.
01 BK         PIC 9(04)       COMP.
01 SK         PIC 9(04)V9     COMP.
01 CNT        PIC 9(05)V9(10) COMP.
01 OT1        PIC ZZZZ9.
01 OT2        PIC 9V9(17).
01 OUT        PIC ZZZZ9.9(10).
*>
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
      INTO A B H M.
*>
  COMPUTE AK = H * 30 + M * 0.5.
  COMPUTE BK = M * 6.
  COMPUTE SK = AK - BK.
  IF (SK > 180)
    COMPUTE SK = 360 - SK
  END-IF.
*>
  EVALUATE TRUE
    WHEN SK = 0
      COMPUTE CNT = A - B
      MOVE CNT TO OUT
      DISPLAY FUNCTION TRIM(OUT)
    WHEN SK = 60
      DISPLAY function sqrt((A ** 2 + B ** 2) - (A * B))
    WHEN SK = 90
      DISPLAY function sqrt(A ** 2 + B ** 2)
    WHEN SK = 120
      DISPLAY function sqrt((A ** 2 + B ** 2) + (A * B))
    WHEN SK = 180
      COMPUTE CNT = A + B
      MOVE CNT TO OUT
      DISPLAY FUNCTION TRIM(OUT)
    WHEN OTHER
      DISPLAY function sqrt((A ** 2 + B ** 2) - (2 * A * B * FUNCTION COS(SK * 3.1415926536 / 180)))
  END-EVALUATE.
*>
*>MOVE CNT TO OUT.
*>DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
