program standartiniai_numeriai;
  { 45 u‘davinys }
{-----------------------------------------------------------}
  const N = 10;    { ISBN numerio skaitmen— skai‡ius }
  type numeris = array [1..N] of char;

  function trukstamas (s : numeris) : char;
    var d,      { daugiklis prie ne‘inomo skaitmens }
        k,      { kontrolinis skaitmuo }
        i, sum : integer;
        rasta : boolean; { ar rastas tinkamas skaitmuo }
  begin
    sum := 0;
    for i := 1 to N - 1 do
      if s[i] in ['0'..'9']
         then sum := sum + i * (ord (s[i]) - ord ('0'))
         else d := i;
    if s[N] = 'X'
       then k := 10
       else k := ord(s[N]) - ord ('0');
    rasta := false;
    i := 0;
    { iežkoma tr–kstamo skaitmens }
    while not rasta and (i <= 9) do
      if (sum + i * d) mod 11 = k
         then rasta := true
         else i := i + 1;
    if rasta
       then trukstamas := chr (i + ord('0'))
       else trukstamas := 'N'
  end;
{-----------------------------------------------------------}
  var i : integer;
      s : numeris;
begin
  write ('­veskite knygos ISBN numer: ');
  for i := 1 to N do
    read (s[i]);
  writeln (trukstamas (s))
end.
