View Single Post
Old 08-11-2006, 06:51 PM   #6
Hồ sơ
myhanh
 
myhanh's Avatar
 
Tham gia ngày: Dec 2004
Cư ngụ: Love Planet
Tuổi: 43
Số bài viết: 7,404
Tiền: 0
Thanks: 2,122
Thanked 5,465 Times in 2,040 Posts
myhanh is on a distinguished road
Default Ðề: Thi HS giỏi cấp tỉnh

program bai2;
const MAX=10;
type diem = record
socot:integer;
diems:array[1..MAX] of integer
end;

procedure xuly(s:string;var d:diem);
const onespace=' ';
twospace=' ';
var p,error:integer;
tam:string;
cont:boolean;
begin
{xoa khoang trang o dau}
while pos(onespace,s) = 1 Do
delete(s,1,1);
s:=s+onespace;
{chuan hoa cac khang trang}
p:= pos(twospace,s);
While (p > 0) do
begin
delete(s,p,2);
insert(onespace,s,p);
p:= pos(twospace,s)
end;
{xu ly so lieu}
p:= pos(onespace,s);
d.socot:=0;
cont:=true;
while(p>0) and cont do
begin
tam:=copy(s,1,p-1);
delete(s,1,p);
inc(d.socot);
if ( d.socot > MAX) then
begin
d.socot := -1;
cont := false
end
else
begin
val(tam,d.diems[d.socot],error);
if( error > 0 ) then
begin
d.socot := -1;
cont := false
end
else
p:= pos(onespace,s)
end
end;
end;
var s1,s2:string;
d1,d2:diem;
d:real;
i:integer;
begin
readln(s1);
readln(s2);
xuly(s1,d1);
xuly(s2,d2);
if( d1.socot = -1 ) or (d2.socot = -1) then
writeln('Co loi trong khi nhap diem')
else
begin
d:=0;
for i:=1 to d1.socot do
d:=d+d1.diems[i];
for i:=1 to d2.socot do
d:=d+d2.diems[i]*2;
d:=d/(d1.socot+2*d2.socot);
writeln('Diem=',d:3:1)
end;
readln
end.
__________________
Necessity is the mother of in(ter)vention.
Speak softly & carry a big stick.
My Technical Blog
myhanh is offline   Trả Lời Với Trích Dẫn