program prevod; const nula = ord('0'); A10 = ord('A')-10; var X, {hledane cislo } K, {zaklad soustavy} cifra : integer; {hodnota cifry} U : char; {cteny znak} UOK, {U je OK} KOK : boolean; {K je OK} begin while not eof do begin read(K); X:=0; KOK:= (2<=K) and (K<=16); repeat read(U) until U<>' '; {preskocil jsem mezery} UOK:=KOK; while U<>' ' do begin write(U); {opisuji vstup} if UOK then {pokud ma smysl pocitat } begin if ('0'<=U) and (U<='9') then cifra:= ord(U)-nula else cifra:=ord(U)-A10; UOK:=(0<=cifra) and (cifra<=K-1); end; if UOK then X:=K*X + cifra; read(U); end; write(' (',K,') '); if not KOK then writeln('Nepripustny zaklad soustavy') else if not UOK then writeln(' Chybna cifra') else writeln('=',X); readln; { pro poradek} end {zpracovani radky } end.