blob: 2d597b733a7dba9e8bd254e93a1f7e481ad0c3e7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
program Ch1;
{$mode objfpc}
uses
SysUtils,Types;
var
Input:Integer;
function FourIsMagic(N:Integer):AnsiString;
var
Words:TStringDynArray = ('one','two','three','four','five',
'six','seven','eight','nine');
Len:Integer;
begin
Result := '';
Len := Length(Words[N-1]);
repeat
Result := Result + Words[N-1] + ' is ' + Words[Len-1] + ', ';
N := Len;
Len := Length(Words[N-1]);
until(N = 4);
Result := Result + 'four is magic.';
Result[1] := UpCase(Result[1]);
end;
begin
if ParamCount < 1 then
begin
WriteLn(StdErr, 'No args provided!');
Halt(1);
end;
if StrToInt(ParamStr(1)) > 9 then
begin
WriteLn(StdErr, 'Number must be less than 10!');
Halt(1);
end;
try
Input := StrToInt(ParamStr(1));
except on E:EConvertError do
Halt(1);
end;
WriteLn(FourIsMagic(Input));
end.
|