- 绕钉子的长绳子
- 2016-03-12 21:50:59 @
var n,r,i:integer;
sum,x,x1,x2,y,y1,y2:real;
begin
readln(n,r);
sum:=2*r*pi;
readln(x,y);
x1:=x;
y1:=y;
for i:=1 to n-1 do begin
readln(x2,y2);
sum:=sum+sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
x1:=x2;
y1:=y2;
end;
sum:=sum+sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
writeln(sum:0:2);
end.
这样错了
pascal
var n,i:integer;
sum,r,x,x1,x2,y,y1,y2,t:real;
begin
readln(n,r);
sum:=2*r*pi;
readln(x,y);
x1:=x;
y1:=y;
for i:=1 to n-1 do begin
readln(x2,y2);
t:=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
sum:=sum+t;
x1:=x2;
y1:=y2;
end;
t:=sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));
sum:=sum+t;
writeln(sum:0:2);
end.
这样就对了?
1 条评论
-
q234rty LV 10 @ 2016-03-13 00:27:42
因为您在第一份代码中把
r
定义成了integer
而非real
- 1