| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
轻松简介小程序var
s:string;
flag:boolean;
a1,a2,b1,b2,c1,c2,i:longint;
function min(a,b:longint):longint;
begin
if abs(a)<abs(b) then exit(a) else exit(b);
end;
procedure plus;
begin
c2:=a2*b2;
c1:=a2*b1+b2*a1;
for i:=min(c1,c2) downto 1 do
if (c1 mod i=0) and (c2 mod i=0) then begin
c1:=c1 div i;
c2:=c2 div i;
end;
if c2=1 then writeln(c1) else
writeln(c1,'/',c2);
end;
procedure minus;
begin
c2:=a2*b2;
c1:=b2*a1-a2*b1;
if c1<0 then flag:=true else flag:=false;
c1:=abs(c1);
for i:=min(c1,c2) downto 1 do
if ((c1 mod i)=0) and ((c2 mod i)=0) then begin
c1:=c1 div i;
c2:=c2 div i;
end;
if c1=0 then writeln(0) else begin
if flag then write('-');
if c2=1 then writeln(c1) else
writeln(c1,'/',c2);
end;
end;
procedure main;
begin
a1:=ord(s[1])-ord('0');
a2:=ord(s[3])-ord('0');
b1:=ord(s[5])-ord('0');
b2:=ord(s[7])-ord('0');
if s[4]='+' then plus;
if s[4]='-' then minus;
end;
begin
readln(s);
while s<>'' do
begin
main;
readln(s);
end;
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator