Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

轻松简介小程序

Posted by qwertybilly at 2011-03-27 11:38:52 on Problem 3979
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator