- 谁拿了最多奖学金
- 2012-07-19 16:25:24 @
(free pascal),那位大哥帮忙看看,一开始用记录:
program ps;
type
studata=record
name:string[20];
exam:integer;
class:integer;
officer:char;
west:char;
write:integer;
money:integer;
end;
var students:array[1..100]of studata;
n,i,j,bestnumber,bestmoney,k:integer;
all:longint;
begin
readln(n);
bestnumber:=0; bestmoney:=0; all:=0;
for i:=1 to n do
begin
with students[j] do
begin
read(name,exam,class,officer,west,write);
students[i].money:=0;
if ((exam>80) and (write>=1)) then money:=money+8000;
if ((exam>85) and (class>80)) then money:=money+4000;
if (exam>90) then money:=money+2000;
if ((exam>85) and (west='Y')) then money:=money+1000;
if ((class>80) and (officer='Y')) then money:=money+850;
if money>bestmoney then begin
bestnumber:=j; bestmoney:=money;
end;
all:=all+money;
end;
end;
writeln(students[bestnumber].name);
writeln(students[bestnumber].money);
writeln(all);
end.
在开域问题上一直很纠结,后来用数组做了,居然还是‘0’
program ps;
var
name:array[1..100] of string;
exam:array[1..100] of integer;
class:array[1..100] of integer;
officer:array[1..100]of char;
west:array[1..100]of char;
write:array[1..100]of integer;
money:array[1..100]of integer;
n,i,j,bestnumber,bestmoney,k:integer;
all:longint;
begin
readln(n);
bestnumber:=0; bestmoney:=0; all:=0;
for i:=1 to n do
begin
read(name[i],exam[i],class[i],officer[i],west[i],write[i]);
money[i]:=0;
if ((exam[i]>80) and (write[i]>=1)) then money[i]:=money[i]+8000;
if ((exam[i]>85) and (class[i]>80)) then money[i]:=money[i]+4000;
if (exam[i]>90) then money[i]:=money[i]+2000;
if ((exam[i]>85) and (west[i]='Y')) then money[i]:=money[i]+1000;
if ((class[i]>80) and (officer[i]='Y')) then
money[i]:=money[i]+850;
if money[i]>bestmoney then begin
bestnumber:=i; bestmoney:=money[i];
end;
all:=all+money[i];
end;
writeln(name[bestnumber]);
writeln(money[bestnumber]);
writeln(all);
end.
那位大哥帮忙啊!
2 条评论
-
seekdreamer LV 7 @ 2012-07-22 16:41:32
oh no
oh no,感谢大哥
-
2012-07-21 14:30:37@
第一个“read(name)”就把那些全读入了吧,string不会遇到空格就停止读入啊。
- 1