Цитата:
Сообщение от Over77over
Но пожалуй сойдет, попробую по аналогии перевести на фортран
|
Не знаю, сколь Вам это поможет, но вот программа на Паскале:
Код:
Var
S,W:String;
i,R,Code:Integer;
Function Six2Ten(N:Integer):Integer;
Var
M,Q,p:Integer;
begin
Q:=N;
p:=1;
M:=Q mod 10;
Repeat
Q:=Q div 10;
if Q>0 then
begin
p:=p*6;
M:=M+(Q mod 10)*p;
end;
Until Q=0;
Six2Ten:=M;
end;
Begin
Writeln('Enter the string:');
ReadLn(S);
i:=0;
Repeat
i:=i+1;
if i<=Length(S) then
begin
if (i=1) or ((i>1) and (S[i-1]=' ') and
((Ord(S[i])>47) and (Ord(S[i])<54))) then
begin
W:='';
repeat
W:=W+S[i];
i:=i+1;
until (i>Length(S)) or (Ord(S[i])<48) or (Ord(S[i])>53);
if (i>Length(S)) or (S[i]=' ') then
begin
Val(W,R,Code);
Writeln;
Write('Six_based: ',R,' Ten_based: ',Six2Ten(R));
end;
end;
end;
Until i>=Length(S);
Readln
End.
На всякий случай:
Val(S,N,Code) - преобразует строку в число. Code - просто флажок корректности операции.
Ord(C) - возвращает код символа C.
div - целочисленное деление.
mod - остаток от деления.