某幼儿园只收2至6岁的小孩,2~3岁入小班,4岁入中班,5~6岁入大班。编写程序输入姓名和年龄,判断小孩入哪个班?并按"姓名 年龄 班级"的格式输出。
用Pascal语言做这道题
- 提问者网友:流星是天使的眼泪
- 2021-05-02 02:18
- 五星知识达人网友:西岸风
- 2021-05-02 03:36
var a,name:string;
len,i,age:longint;
begin
read(a);
len:=length(a);
for i:=1 to len do begin
if (a[i]>='a') and (a[i]<='z') or (a[i]>='A') and (a[i]<='Z')then begin
name[i]:=a[i];
end
else if (a[i]>='0') and (a[i]<='9') then age:=age*10+ord(a[i])-48;
end;
write(name,' 'age,' ');
case age of
2,3:write('xiaoban');
4:write(zhongban);
5,6:write('daban');
end;
if (age<2) or (age>6) then write('Error!');
end.
如果有细节性错误请原谅、不是很习惯直接在网页上写程序。
- 1楼网友:刀戟声无边
- 2021-05-02 05:10
const MAXNM=100;
var a:array[1..MAXNM] of record
name:string[20];
age:byte;
class:byte;
end;
n,i:integer;
begin
read(n);
for i:=1 to n do
begin
with a[i] do
begin
class:=0;
readln(name);
readln(age);
if (age>=2) and (age<=3) then class:=1;
else if age=4 then class:=2;
else if age<=6 then class:=3;
end;
end;
for i:=1 to n do
begin
with a[i] do
begin
write(name," ",age," ");
case class of
0: writeln("未知班级");
1: writeln("小班");
2: writeln("中班");
3: writeln("大班");
else writeln("错误!");
end;
end;
end;
readln;
end.
很久不写P语言了,有错误的话希望谅解