比这篇新的文章:
humble.cpp
比这篇旧的文章: butter.cpp
作者: xpycc, 点击247次, 评论(0), 收藏者(0)
打分:
所有评论,共0条:( 我也来说两句)
比这篇旧的文章: butter.cpp
ratios.pas
语言: Delphi, 标签: 无 2008/08/22发布 3个月前更新作者: xpycc, 点击247次, 评论(0), 收藏者(0)
Delphi语言: ratios.pas
01 {
02 ID:xpycc1
03 PROG:ratios
04 LANG:PASCAL
05 }
06
07 program ratios;
08 var
09 x,y,z,x1,y1,z1,x2,y2,z2,x3,y3,z3,a,b,c,d,
10 tem1,tem2,tem3,t:longint;
11 //
12 function gcd(i,j:longint):longint;
13 var h:longint;
14 begin
15 if i<j then
16 begin
17 h:=i; i:=j; j:=h;
18 end;
19 if i mod j=0 then gcd:=j
20 else gcd:=gcd(j,i mod j);
21 end;
22 //
23 begin
24 assign(input,'ratios.in'); reset(input);
25 readln(x,y,z);
26 readln(x1,y1,z1);
27 readln(x2,y2,z2);
28 readln(x3,y3,z3);
29 close(input);
30
31 //分母
32 tem1:=x3*y2*z1 - x2*y3*z1 - x3*y1*z2 + x1*y3*z2 + x2*y1*z3 - x1*y2*z3;
33 tem2:=x2*y3*z1 + x3*y1*z2 - x1*y3*z2 - x2*y1*z3 + x1*y2*z3 - x3*y2*z1;
34 tem3:=x3*y2*z1 - x2*y3*z1 - x3*y1*z2 + x1*y3*z2 + x2*y1*z3 - x1*y2*z3;
35 //分子
36 a:=x3*y2*z - x2*y3*z - x3*y*z2 + x*y3*z2 + x2*y*z3 - x*y2*z3;
37 b:=x3*y1*z - x1*y3*z - x3*y*z1 + x*y3*z1 + x1*y*z3 - x*y1*z3;
38 c:=x2*y1*z - x1*y2*z - x2*y*z1 + x*y2*z1 + x1*y*z2 - x*y1*z2;
39 if tem1<0 then //把分母变成正数
40 begin tem1:=-tem1; a:=-a; end;
41 if tem2<0 then
42 begin tem2:=-tem2; b:=-b; end;
43 if tem3<0 then
44 begin tem3:=-tem3; c:=-c; end;
45 //无解的情况
46 if(tem1=0)or(tem2=0)or(tem3=0)or(a<0)or(b<0)or(c<0)then
47 begin
48 assign(output,'ratios.out'); rewrite(output);
49 writeln('NONE'); close(output); halt;
50 end else begin
51 t:=gcd(tem1,tem2);
52 t:=gcd(t,tem3);
53 d:=t*(tem1 div t)*(tem2 div t)*(tem3 div t);
54 end;
55 a:=a*(tem2 div t)*(tem3 div t);
56 b:=b*(tem1 div t)*(tem3 div t);
57 c:=c*(tem1 div t)*(tem2 div t);
58
59 if a=0 then t:=b //处理答案中的0
60 else if b=0 then t:=a //注意a,b可能都是0
61 else t:=gcd(a,b);
62 if t=0 then t:=c //注意若有解a,b,c不会同时为0
63 else t:=gcd(t,c);
64 t:=gcd(t,d); //若有解d一定不为0
65
66 a:=a div t;
67 b:=b div t;
68 c:=c div t;
69 d:=d div t;
70 assign(output,'ratios.out'); rewrite(output);
71 writeln(a,' ',b,' ',c,' ',d);
72 close(output);
73 end.
02 ID:xpycc1
03 PROG:ratios
04 LANG:PASCAL
05 }
06
07 program ratios;
08 var
09 x,y,z,x1,y1,z1,x2,y2,z2,x3,y3,z3,a,b,c,d,
10 tem1,tem2,tem3,t:longint;
11 //
12 function gcd(i,j:longint):longint;
13 var h:longint;
14 begin
15 if i<j then
16 begin
17 h:=i; i:=j; j:=h;
18 end;
19 if i mod j=0 then gcd:=j
20 else gcd:=gcd(j,i mod j);
21 end;
22 //
23 begin
24 assign(input,'ratios.in'); reset(input);
25 readln(x,y,z);
26 readln(x1,y1,z1);
27 readln(x2,y2,z2);
28 readln(x3,y3,z3);
29 close(input);
30
31 //分母
32 tem1:=x3*y2*z1 - x2*y3*z1 - x3*y1*z2 + x1*y3*z2 + x2*y1*z3 - x1*y2*z3;
33 tem2:=x2*y3*z1 + x3*y1*z2 - x1*y3*z2 - x2*y1*z3 + x1*y2*z3 - x3*y2*z1;
34 tem3:=x3*y2*z1 - x2*y3*z1 - x3*y1*z2 + x1*y3*z2 + x2*y1*z3 - x1*y2*z3;
35 //分子
36 a:=x3*y2*z - x2*y3*z - x3*y*z2 + x*y3*z2 + x2*y*z3 - x*y2*z3;
37 b:=x3*y1*z - x1*y3*z - x3*y*z1 + x*y3*z1 + x1*y*z3 - x*y1*z3;
38 c:=x2*y1*z - x1*y2*z - x2*y*z1 + x*y2*z1 + x1*y*z2 - x*y1*z2;
39 if tem1<0 then //把分母变成正数
40 begin tem1:=-tem1; a:=-a; end;
41 if tem2<0 then
42 begin tem2:=-tem2; b:=-b; end;
43 if tem3<0 then
44 begin tem3:=-tem3; c:=-c; end;
45 //无解的情况
46 if(tem1=0)or(tem2=0)or(tem3=0)or(a<0)or(b<0)or(c<0)then
47 begin
48 assign(output,'ratios.out'); rewrite(output);
49 writeln('NONE'); close(output); halt;
50 end else begin
51 t:=gcd(tem1,tem2);
52 t:=gcd(t,tem3);
53 d:=t*(tem1 div t)*(tem2 div t)*(tem3 div t);
54 end;
55 a:=a*(tem2 div t)*(tem3 div t);
56 b:=b*(tem1 div t)*(tem3 div t);
57 c:=c*(tem1 div t)*(tem2 div t);
58
59 if a=0 then t:=b //处理答案中的0
60 else if b=0 then t:=a //注意a,b可能都是0
61 else t:=gcd(a,b);
62 if t=0 then t:=c //注意若有解a,b,c不会同时为0
63 else t:=gcd(t,c);
64 t:=gcd(t,d); //若有解d一定不为0
65
66 a:=a div t;
67 b:=b div t;
68 c:=c div t;
69 d:=d div t;
70 assign(output,'ratios.out'); rewrite(output);
71 writeln(a,' ',b,' ',c,' ',d);
72 close(output);
73 end.
所有评论,共0条:( 我也来说两句)
代码