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

终于,交了4次后,了解了题目要求(pascal)

Posted by bage at 2010-12-16 14:55:08 on Problem 3979
var
w,i,k,c:longint;
a:array[1..7] of char;
t:array[1..5] of longint;
function gcd(x,y:longint):longint;
 begin
  if x=0 then exit(y);
  if y=0 then exit(x);
  if x mod y=0 then exit(y);
  exit(gcd(y,x mod y));
 end;

 begin
  {assign(input,'3.in');
  assign(output,'3.out');
  reset(input);
  rewrite(output);}
   while not eof do
    begin
     for i:=1 to 7 do
       read(a[i]);
       val(a[1],t[1]);
       val(a[3],t[2]);
       val(a[5],t[3]);
       val(a[7],t[4]);

     k:=t[2]*t[4];
     case a[4] of
      '-':begin
           c:=k div t[2]*t[1]-k div t[4]*t[3];
           if c<0 then write('-');
           w:=gcd(abs(c),k);
           if abs(c) mod k=0 then begin
            writeln(abs(c) div k);
            readln;
            continue;
             end;
      if c div w=0 then writeln(0)
           else
            writeln(abs(c) div w,'/',k div w);

          end;
       '+':begin
             c:=k div t[2]*t[1]+k div t[4]*t[3];
               if abs(c) mod k=0 then begin
            writeln(abs(c) div k);
            readln;
            continue;
             end;
           w:=gcd(abs(c),k);
           if c div w=0 then writeln(0)
            else
             writeln(c div w,'/',k div w);

           end;
       end;
        readln;
      end;
     {close(input);
     close(output);}
    end.
0ms AC
表示无压力

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