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 |
终于,交了4次后,了解了题目要求(pascal)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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator