program Bio97q1; { Problem statement: Write a program which inputs the time on a twelve hour clock and then prints the time in words. Examples: 4.00 four o'clock 10.12 twelve minutes past ten 12.15 quarter past twelve 12.45 quarter to one 12.59 one minute to twelve } { See copyright notice at the end of this file. } { For Delphi or Turbo Pascal for Windows, include this line } { uses WinCrt; } { otherwise comment it out. } const Num2Word: array[0..29] of String = ( 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twenty-one', 'twenty-two', 'twenty-three', 'twenty-four', 'twenty-five', 'twenty-six', 'twenty-seven', 'twenty-eight', 'twenty-nine' ); var Hours, Minutes, Status: integer; TheTime: String; function Time2Word(Hours, Minutes: integer): String; var S: String; begin { check for special cases } if Minutes > 30 then begin Hours := Hours + 1; if Hours = 13 then Hours := 1; end; case Minutes of 0: S := Num2Word[Hours] + ' o''clock'; 1: S := 'one minute past ' + Num2Word[Hours]; 15: S := 'quarter past ' + Num2Word[Hours]; 30: S := 'half past ' + Num2Word[Hours]; 45: S := 'quarter to ' + Num2Word[Hours]; 59: S := 'one minute to ' + Num2Word[Hours] else begin if Minutes < 30 then S := Num2Word[Minutes] + ' minutes past ' + Num2Word[Hours] else S := Num2Word[60 - Minutes] + ' minutes to ' + Num2Word[Hours]; end; end; Time2Word := S; end; begin WriteLn('Please enter the time on the twelve-hour clock ', 'in the form hh mm'); Write('>'); ReadLn( Hours, Minutes ); WriteLn('The time is ', Time2Word(Hours, Minutes), ' (', Hours:1, '.', Minutes:1, ')'); WriteLn; WriteLn('End of program'); end. { Solution copyright (c) 1997 The British Informatics Olympiad (BIO). This program may be freely copied by persons or organisations involved in the British Informatics Olympiad or the International Olympiad in Informatics, on condition that no changes are made and this notice is not altered. Distribution for profit is forbidden unless permission is first obtained in writing from the BIO. This program is for educational purposes only and comes with no warranty, implied or otherwise, as to its fitness for any purpose. Author: Antony Rix Internet: http://www.christs.cam.ac.uk/bio/ E-mail: a.rix@lineone.net S-mail: The British Informatics Olympiad Christ's College Cambridge CB2 3BU United Kingdom }