public
Description: My solutions for problems from the UVa Online Judge (Valladolid).
Homepage: http://icpcres.ecs.baylor.edu/onlinejudge/
Clone URL: git://github.com/andmej/acm.git
acm / 10127 - Ones / p10127.~dpr
100755 43 lines (37 sloc) 0.754 kb
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
program p10127;
 
{$APPTYPE CONSOLE}
 
function procesar(n : integer) : integer;
var
  tabla : Array[0..9] of integer;
  carry, multiplo, i, ultimaCifra : integer;
begin
  result := 0;
  for i := 0 to 9 do
    tabla[i] := n * i;
  ultimaCifra := 1;
  carry := 0;
 
  repeat
    //2
    multiplo := 0;
    while tabla[multiplo] mod 10 <> ultimaCifra do
      multiplo := multiplo + 1;
    //3 y 5
    carry := (n * multiplo + carry) div 10;
    //4
    result := result + 1;
    //6
    i := carry;
    while (i mod 10 <> 1) do
      i := i + 1;
    ultimaCifra := i - carry;
  until carry = 0;
 
end;
 
var
  n : integer;
begin
  while not EOF do
    begin
      readLn(n);
      writeLn(procesar(n));
    end;
end.