blob: a6abd97b4b6b4b911f5b8a41c53319f8732abcac (
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
45
46
47
48
49
50
51
52
53
54
55
56
|
Program XXX;
(* *)
(* See ../README.md *)
(* *)
(* *)
(* Run as: fpc -och-2.out ch-2.p; ./ch-2.out < input-file *)
(* *)
uses
RegExpr;
const
ord_0 = Ord ('0');
ord_9 = Ord ('9');
ord_A = Ord ('A');
w : Array [0 .. 6] of Integer = (1, 3, 1, 7, 3, 9, 1);
var
sedol: String;
valid: TRegExpr;
check: Integer;
c: Char;
val: Integer;
index: Integer;
begin
valid := TRegExpr . Create ('^[0-9BCDFGHJKLMNPQRSTVWXYZ]{6}[0-9]$');
while not eof do begin
readln (sedol);
if not valid . Exec (sedol) then begin
writeln (0);
continue;
end;
check := 0;
index := 0;
for c in sedol do begin
val := Ord (c);
if val <= ord_9 then begin
val := val - ord_0;
end
else begin
val := val - ord_A;
end;
check := check + val * w [index];
inc (index);
end;
if check mod 10 = 0 then begin
writeln (1);
end
else begin
writeln (0);
end
end
end.
|