Pascal编写程序,高手进

输入一字符串,以*号结束,指出该字符串出现的小写字母。
2025-02-27 10:09:50
推荐回答(3个)
回答1:

你好!这是我写的,在lazarus下编译成功。
program zimu;
var ch:char;
begin
assign(input,'zimu.in');
assign(output,'zimu.out');
reset(input);
rewrite(output);
read(ch);
while ch<>'*' do begin
if (ch>='a') and (ch<='z') then writeln(ch);
read(ch);
end;
close(input);
close(output);
end.
具体过程:read(ch);先读入一个字符,因为用while循环要先对控制变量ch赋值,read语句不但有读入的意思,同时还对变量进行了赋值。
while ch<>'*' do begin
……
end;
ch<>'*'是执行while循环的条件,当ch='*'时(即读到最后一个字符时),退出循环。
if (ch>='a') and (ch<='z'):如果ch是小写英文字母。因为英文字符可以直接比较大小,所以(ch>='a') and (ch<='z')就是指ch是小写英文字母。
then writeln(ch);那么输出ch并换行
read(ch);再读入下一个字符,留给下一次循环检验。
已经很详细了,希望可以帮你。

回答2:

c语言行吗?

回答3:

美观起见,将每行的缩进空格改为符号`,请用记事本替换回空格符

program lowch;

var
``a:array['a'..'z'] of longint;
``b,c:char;

begin
``fillchar(a,sizeof(a),0);
``c:=' ';
``while c<>'*' do begin
````read(c);
````if (c>='a') and (c<='z') then inc(a[c]);
``end;
``for b:='a' to 'z' do
````if a[b]>0 then writeln(b,' -> ',a[b]);
``readln;
``readln;
end.