Re: Задача по Turbo Pascal
Добавлено: 02 апр 2008, 10:53
Ну, сказано было - синтаксически верно, а не лексически. Синтаксически действительно все верно.
Спасибо, поправил. ОпечаткаC_O_D_E писал(а):и кстати процедура вывода на экран Writeln , а в коде Writelen
Ребят, ну вы ЧЕГО?C_O_D_E писал(а):Следовательно, он закрывает НЕ предыдущую строку, а иенно текущую?!
Да, не необходима, но и не является ошибочной.C_O_D_E писал(а):после Begin, a соответственно и перед i:=1 точка с запятой не нужна.![]()
Код: Выделить всё
Statements
============
A statement is one of the following:
assignment (:=)
begin..end
case..of..else..end
for..to/downto..do
goto
if..then..else
inline(...)
procedure call
repeat..until
while..do
with..do
Код: Выделить всё
const
N=100;
var
words:array[1..N]of string;
w:array[1..N]of string;
cn,k:integer;
s:string;
wd:string;
i,j:integer;
index:integer;
count:integer;
cnt:integer;
max:integer;
wc:integer;
b:boolean;
function ParceText(txt:string):integer;
var l,c:integer;
begin
c:=0;
l:=length(txt);
for i:=1 to l+1 do
begin
if ((txt[i]<>' ')and(i<>l+1)) then
wd:=wd+txt[i]
else
begin
inc(c);
words[c]:=wd;
wd:='';
end;
end;
ParceText:=c;
end;
begin
writeln('Введите текст:');
readln(s);
count:=ParceText(s);
for i:=1 to count do
begin
cnt:=0;
for j:=1 to count do
if words[j]=words[i] then
inc(cnt);
if cnt>max then
begin
max:=cnt;
index:=i;
end;
end;
writeln;
writeln('Чаще всего встречаются слова:');
for i:=1 to count do
begin
wc:=0;
for j:=1 to count do
if words[i]=words[j] then
inc(wc);
if wc=max then
begin
b:=true;
for k:=1 to cn do
if w[k]=words[i] then
b:=false;
if b then
begin
writeln(words[i]);
inc(cn);
w[cn]:=words[i];
end;
end;
end;
readln;
end.
Нужно вставить приведенный код вместоassis2007 писал(а):А можно прямо относительно моего кода? т.е. прямо в нем исправить
Код: Выделить всё
writeln('Введите текст:');
readln(s);
count:=ParceText(s);
Код: Выделить всё
c:=0;
Небольшой совет по коду- красоты ради обьединяйте переменные одного типа при их объявлении" писал(а):У меня вопрос по коду
Код: Выделить всё
const
N=100;
var
words:array[1..N]of string;
w:array[1..N]of string;
cn,k:integer;
s:string;
wd:string;
i,j:integer;
isk_slovo:integer;
kolislov:integer;
kolpovt:integer;
max,m,c:integer;
wc:integer;
a,b:boolean;
function Kolslov(txt:string):integer;
var
l,c:integer;
begin
l:=length(txt);
for i:=1 to l+1 do
begin
if ((txt[i]<>' ')and(i<>l+1)) then
wd:=wd+txt[i]
else
begin
c:=c+1;
words[c]:=wd;
wd:='';
end;
end;
if c>10 then
begin
writeln('Obrabativaetsa tolko 10 slov');
Kolslov:=10;
end
else
Kolslov:=c;
end;
begin
writeln('Vvedite tekst');
m:=0;
repeat
readln(s);
if s<>'$' then
begin
inc(m);
words[m]:=S;
end;
until s='$';
kolislov:=kolslov(s);
a:=false;
if kolislov>1 then
begin
for i:=1 to kolislov do
begin
kolpovt:=0;
for j:=1 to kolislov do
if words[j]=words[i] then
kolpovt:=kolpovt+1;;
if kolpovt>1 then
begin
isk_slovo:=i;
a:=true;
end;
end;
writeln;
if a then
begin
writeln('Clova vstrechayshiesa bolee odnogo raza:');
for i:=1 to kolislov do
begin
wc:=0;
for j:=1 to kolislov do
if words[i]=words[j] then
inc(wc);
if wc>1 then
begin
b:=true;
for k:=1 to cn do
if w[k]=words[i] then
b:=false;
if b then
begin
writeln(words[i]);
inc(cn);
w[cn]:=words[i];
end;
end;
end;
end
else
writeln('V texte net slov povtorayshihsa bolee odnogo raza');
end
else
writeln('Text otsytstvyet');
readln;
end.