Другие языки программирования и технологии

Сделал программу в паскале, но ее нужно доправить.

Var s,s2:string; i:integer;

Begin
readln (s2);
s2:=s2 + ' ';
While i<=length(s) do begin
i:=i+1;
s:='';
While s2[i] <> ' ' do begin
if s='.-' then write('A');
if s='-...' then write('Б');
if s='.--' then write('В');
if s='--.' then write('Г');
if s='-..' then write('Д');
if s='.' then write('Е');
if s='...-' then write('Ж');
if s='--..' then write('З');
if s='..' then write('И');
if s='.---' then write('Й');
if s='-.-' then write('К');
if s='.-..' then write('Л');
if s='--' then write('М');
if s='-' then write('Н');
if s='---' then write('О');
if s='.--.' then write('П');
if s='.-.' then write('Р');
if s='...' then write('С');
if s='-' then write('Т');
if s='..-' then write('У');
if s='..-.' then write(' Ф');
if s='....' then write('Х');
if s='-.-.' then write('Ц');
if s='---.' then write('Ч');
if s='----' then write('Ш');
if s='--.-' then write('Щ');
if s='.--.-' then write('Ъ');
if s='-.--' then write('Ы');
if s='-..-' then write('Ь');
if s='..-.' then write('Э');
if s='..--' then write('Ю');
if s='.-.-' then write('Я');
s:=s+s2[i];
i:=i+1;
fn(s);
End;
End;
End.

Программа для перевода из морзянки в слово. Помогите пожалуйста.
|Dimka| |Gutorov|
|Dimka| |Gutorov|
1 288
Что за три целых, четырнадцать сотых у тебя. Неужели сложно все организовать в массиве
Тима Вагин
Тима Вагин
12 784
Лучший ответ
|Dimka| |Gutorov| В смыcле 3,14? Где?
Эти if s='.-' then write('A');if s='-...' then write('Б');if s='.--' then write('В');if s='--.' then write('Г');if s='-..' then write('Д') ---явно слишком длинно и излишне. Паскаль не знаю, но на Javascript сделал бы куда короче. Для начала так

var morse = ['.-', '-...', '.--', '--.'];
var letters = ['А','Б','В','Г'];
var l = prompt('введите русскую букву');
l = l.toLowerCase();
for (var i = 0; i < letters.length; i++) {
if (letters[i].toLowerCase() == l) {
alert('в морзянке это будет ' + morse[i]);
}
};
'Н' и 'Т' обозначены одним кодом
Var s,s2:string; i:integer;

procedure fn(s: string);
begin
if s='.-' then write('A');
if s='-...' then write('Б');
if s='.--' then write('В');
if s='--.' then write('Г');
if s='-..' then write('Д');
if s='.' then write('Е');
if s='...-' then write('Ж');
if s='--..' then write('З');
if s='..' then write('И');
if s='.---' then write('Й');
if s='-.-' then write('К');
if s='.-..' then write('Л');
if s='--' then write('М');
if s='-.' then write('Н');
if s='---' then write('О');
if s='.--.' then write('П');
if s='.-.' then write('Р');
if s='...' then write('С');
if s='-' then write('Т');
if s='..-' then write('У');
if s='..-.' then write(' Ф');
if s='....' then write('Х');
if s='-.-.' then write('Ц');
if s='---.' then write('Ч');
if s='----' then write('Ш');
if s='--.-' then write('Щ');
if s='.--.-' then write('Ъ');
if s='-.--' then write('Ы');
if s='-..-' then write('Ь');
if s='..-.' then write('Э');
if s='..--' then write('Ю');
if s='.-.-' then write('Я');
end;

Begin
readln (s2);/// -./---/.../-/.-./.-/-../.-/--/..-/...
s2:=trim(s2)+' ';
repeat
i:=i+1;
s:='';
While s2[i] in ['.','-'] do begin
s:=s+s2[i];
i:=i+1;
End;
for j:integer:=1 to length(s) do
case s[j] of
'.':System.Console.Beep(1200, 200);
'-':System.Console.Beep(1200, 600);
end;
Sleep(900); //пауза между буквами
fn(s);
until i>=length(s2);
End.