pascal问题,求用string做:求输入一句英文句子,求所有单词的平均长度.
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/09/22 03:46:55
pascal问题,求用string做:求输入一句英文句子,求所有单词的平均长度.
要用最最最简洁、简单的做出来,谢谢!
要用最最最简洁、简单的做出来,谢谢!
① 平均长度,用了浮点,如果有需要,可以改成整数② 统计是以a~z,A~Z,以及' - 为单词进行的,如果有需要,也可以改成只按字母统计.program words_average_length;
var
instr : String;
word_cnt, word_lengths, i : Integer;
isWordCount : Boolean;
begin
readln(instr);
word_cnt := 0; word_lengths := 0; isWordCount := false;
for i := 1 to length(instr) do
begin
if instr[i] in ['A'..'Z','a'..'z','''','-'] then
begin
inc(word_lengths);
if not isWordCount then begin isWordCount := true; inc(word_cnt); end
end
else
begin if isWordCount then isWordCount := false; end;
end;
writeln('word count = ', word_cnt);
writeln('word length sum = ', word_lengths);
writeln('word length average = ', word_lengths / word_cnt:10:2);
end.③ 运行:this's A Test!
word count = 3
word length sum = 11
word length average = 3.67
再问: 就是可以用最简单的只用string里面的函数,不要用in,not什么的,还不会用那种,就只需要用string就好了,并且不要用boolean好吗?
再答: program words_average_length;
var
instr : String;
word_cnt, word_lengths, i, isWordCount : Integer;
begin
readln(instr);
word_cnt := 0; word_lengths := 0; isWordCount := 0;
for i := 1 to length(instr) do
begin
if ( (instr[i] >= 'A') and (instr[i] <= 'Z') or
(instr[i] >= 'a') and (instr[i] <= 'z') or
(instr[i] = '''') or (instr[i] = '-') ) then
begin
inc(word_lengths);
if isWordCount = 0 then begin isWordCount := 1; inc(word_cnt); end
end
else
begin if isWordCount = 1 then isWordCount := 0; end;
end;
writeln('word count = ', word_cnt);
writeln('word length sum = ', word_lengths);
writeln('word length average = ', word_lengths / word_cnt:10:2);
end.
var
instr : String;
word_cnt, word_lengths, i : Integer;
isWordCount : Boolean;
begin
readln(instr);
word_cnt := 0; word_lengths := 0; isWordCount := false;
for i := 1 to length(instr) do
begin
if instr[i] in ['A'..'Z','a'..'z','''','-'] then
begin
inc(word_lengths);
if not isWordCount then begin isWordCount := true; inc(word_cnt); end
end
else
begin if isWordCount then isWordCount := false; end;
end;
writeln('word count = ', word_cnt);
writeln('word length sum = ', word_lengths);
writeln('word length average = ', word_lengths / word_cnt:10:2);
end.③ 运行:this's A Test!
word count = 3
word length sum = 11
word length average = 3.67
再问: 就是可以用最简单的只用string里面的函数,不要用in,not什么的,还不会用那种,就只需要用string就好了,并且不要用boolean好吗?
再答: program words_average_length;
var
instr : String;
word_cnt, word_lengths, i, isWordCount : Integer;
begin
readln(instr);
word_cnt := 0; word_lengths := 0; isWordCount := 0;
for i := 1 to length(instr) do
begin
if ( (instr[i] >= 'A') and (instr[i] <= 'Z') or
(instr[i] >= 'a') and (instr[i] <= 'z') or
(instr[i] = '''') or (instr[i] = '-') ) then
begin
inc(word_lengths);
if isWordCount = 0 then begin isWordCount := 1; inc(word_cnt); end
end
else
begin if isWordCount = 1 then isWordCount := 0; end;
end;
writeln('word count = ', word_cnt);
writeln('word length sum = ', word_lengths);
writeln('word length average = ', word_lengths / word_cnt:10:2);
end.
pascal问题,求用string做:求输入一句英文句子,求所有单词的平均长度.
求输入英文句子单词的平均长度.
用VB编程,求输入的英语句子中单词的平均长度
输入一个自然数,求这个自然数的所有约数之和,用PASCAL语言
用VB编写过程,计算输入英文句子中单词的平均长度
单词连接 (link.pas/c/cpp)pascal语言的问题,求pascal程序详细内容
输入一个自然数X,求这个自然数的所有约数之积S.(Pascal)
pascal问题求输出
pascal问题,求程序:
c++ 输入一句话,求单词的长度和出现次数
pascal中求质数的问题.
pascal 题,输入5个正整数求它们的最大公约数.