MODIFICAR CODIGO
Publicado por Mjuiz (9 intervenciones) el 14/01/2005 15:17:37
¿Cómo podría modificar el siguiente código en PASCA ESTANDAR para que, en vez de devolver el número total de palabras que contiene un texto, devolviese las once palabras que más se repiten y la respectiva frecuencia de cada una, ordenadas de mayor a menor frecuencia?
Gracias.
program Contar_Palabras (input, output, infile );
type oneline = packed array[1..81] of char;
{ Función que determina si un carácter es alfabético }
function alphabetic ( ch : char ) : boolean;
begin
if ( ((ch >= 'a') AND (ch <= 'z')) OR ((ch >= 'A') AND (ch <= 'Z')) ) then
alphabetic := TRUE
else
alphabetic := FALSE
end;
{ Función que cuenta el número de palabras en un string }
function count_words ( var line : oneline ) : integer;
var i, word_count : integer;
looking_for_word : boolean;
begin
looking_for_word := TRUE;
word_count := 0;
for i := 1 to 81 do
begin
if alphabetic( line[i] ) then
begin
if looking_for_word then
begin
word_count := word_count + 1;
looking_for_word := FALSE
end
end
else
looking_for_word := TRUE
end;
count_words := word_count
end;
var infile : text;
tline : oneline;
fname : string[15];
total,count : integer;
ch : char;
begin
total := 0;
writeln('Please enter name of input file to count');
readln (fname);
assign (infile, fname);
reset( infile);
while not eof(infile) do
begin
for count := 1 to 81 do
tline[count] := ' ';
count := 1;
while not eoln(infile) do
begin
read(infile, ch );
tline[count] := ch;
count := count + 1
end;
total := total + count_words( tline );
readln(infile) { read eoln character }
end;
writeln('Hay ',total, ' palabras en el texto.')
end.
Gracias.
program Contar_Palabras (input, output, infile );
type oneline = packed array[1..81] of char;
{ Función que determina si un carácter es alfabético }
function alphabetic ( ch : char ) : boolean;
begin
if ( ((ch >= 'a') AND (ch <= 'z')) OR ((ch >= 'A') AND (ch <= 'Z')) ) then
alphabetic := TRUE
else
alphabetic := FALSE
end;
{ Función que cuenta el número de palabras en un string }
function count_words ( var line : oneline ) : integer;
var i, word_count : integer;
looking_for_word : boolean;
begin
looking_for_word := TRUE;
word_count := 0;
for i := 1 to 81 do
begin
if alphabetic( line[i] ) then
begin
if looking_for_word then
begin
word_count := word_count + 1;
looking_for_word := FALSE
end
end
else
looking_for_word := TRUE
end;
count_words := word_count
end;
var infile : text;
tline : oneline;
fname : string[15];
total,count : integer;
ch : char;
begin
total := 0;
writeln('Please enter name of input file to count');
readln (fname);
assign (infile, fname);
reset( infile);
while not eof(infile) do
begin
for count := 1 to 81 do
tline[count] := ' ';
count := 1;
while not eoln(infile) do
begin
read(infile, ch );
tline[count] := ch;
count := count + 1
end;
total := total + count_words( tline );
readln(infile) { read eoln character }
end;
writeln('Hay ',total, ' palabras en el texto.')
end.
Valora esta pregunta


0