Другие языки программирования и технологии
Помогите пожалуйста на Паскале
дан текст, содержащий слова на латинице, разделенные пробелами.Определить какие буквы в словах совпадают чаще:первые, последние или вторые и предпоследние
program VeryEasy;
const
letters : set of char = ['A'..'z', 'a'..'z'];
function GetWordsCount(Str: string): integer;
var
found: boolean;
i: integer;
r: integer;
begin
r := 0;
i := 1;
repeat
found := false;
while (i <= Length(Str))and(not(Str[ i ] in letters)) do
inc(i);
while (i <= Length(Str))and(Str[ i ] in letters) do begin
found := true;
inc(i);
end;
if found then
r := r + 1;
until (i >= Length(Str))or(not found);
GetWordsCount := r;
end;
function GetWordById(Str: string; Id: integer): string;
var
i, k: integer;
r : string;
begin
r := '';
i := 1;
k := 1;
repeat
GetWordById := '';
while (i <= Length(Str))and(not(Str[ i ] in letters)) do
inc(i);
while (i <= Length(Str))and(Str[ i ] in letters) do begin
if (k = Id) then
r := r+Str[ i ];
inc(i);
end;
inc(k);
until (i >= Length(Str))or(k = Id+1);
GetWordById := r;
end;
var
n1, n2, i : integer;
text, buf : string;
begin
readln(text);
n1 := 0;
n2 := 0;
for i := 1 to GetWordsCount(Text) do begin
buf := GetWordById(Text, i);
if (Length(buf) > 0)and(buf[1] = buf[Length(buf)]) then
n1 := n1 + 1;
if (Length(buf) > 1)and(buf[2] = buf[Length(buf)-1]) then
n2 := n2 + 1;
end;
if n1 = n2 then
writeln('Equally')
else
if n1 > n2 then
writeln('1&N more')
else
writeln('2&(N-1) more');
readln;
end.
const
letters : set of char = ['A'..'z', 'a'..'z'];
function GetWordsCount(Str: string): integer;
var
found: boolean;
i: integer;
r: integer;
begin
r := 0;
i := 1;
repeat
found := false;
while (i <= Length(Str))and(not(Str[ i ] in letters)) do
inc(i);
while (i <= Length(Str))and(Str[ i ] in letters) do begin
found := true;
inc(i);
end;
if found then
r := r + 1;
until (i >= Length(Str))or(not found);
GetWordsCount := r;
end;
function GetWordById(Str: string; Id: integer): string;
var
i, k: integer;
r : string;
begin
r := '';
i := 1;
k := 1;
repeat
GetWordById := '';
while (i <= Length(Str))and(not(Str[ i ] in letters)) do
inc(i);
while (i <= Length(Str))and(Str[ i ] in letters) do begin
if (k = Id) then
r := r+Str[ i ];
inc(i);
end;
inc(k);
until (i >= Length(Str))or(k = Id+1);
GetWordById := r;
end;
var
n1, n2, i : integer;
text, buf : string;
begin
readln(text);
n1 := 0;
n2 := 0;
for i := 1 to GetWordsCount(Text) do begin
buf := GetWordById(Text, i);
if (Length(buf) > 0)and(buf[1] = buf[Length(buf)]) then
n1 := n1 + 1;
if (Length(buf) > 1)and(buf[2] = buf[Length(buf)-1]) then
n2 := n2 + 1;
end;
if n1 = n2 then
writeln('Equally')
else
if n1 > n2 then
writeln('1&N more')
else
writeln('2&(N-1) more');
readln;
end.
ну и че сложного через If
Похожие вопросы
- Помогите пожалуйста с паскалем...я его только осваиваю(
- Помогите пожалуйста с паскалем!!!
- Помогите пожалуйста с паскалем!
- Помогите пожалуйста по паскалю.
- Помогите пожалуйста с паскалем)))
- Дан двумерный массив C(m,n). Найти произведение элементов, больших среднего значения. Помогите пожалуйста!!! На паскале
- Помогите пожалуйста на Паскале или С#
- Помогите, пожалуйста. Программирование паскаль, однонаправленные списки.
- Ребят помогите пожалуйста. Паскаль, Paskal
- Помогите пожалуйста с Заданием по Паскалю!