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 |
Re:终于出来了(pascal)In Reply To:终于出来了(pascal) Posted by:wy54224 at 2011-01-26 16:00:20 program poj3979; var s,s1,s2,ss1,ss2:string; x1,x2,y1,y2,jl,code:integer; function zdgys(a,b:integer):integer; var ab,i,max:integer; begin if a>b then ab:=a else ab:=b; max:=1; for i:=1 to ab do if (a mod i=0)and(b mod i=0)then max:=i; zdgys:=max; end; procedure init; var i:integer; procedure main; var c:char; op1,op2,op3,i:integer; begin op1:=0;op2:=0;op3:=0; for i:=1 to length(s)do begin c:=s[i]; if c='+'then begin jl:=1; s1:=copy(s,1,i-1); delete(s,1,i); s2:=s; break; end; if c='-'then begin jl:=2; s1:=copy(s,1,i-1); delete(s,1,i); s2:=s; break; end; end; for i:=1 to length(s1)do begin c:=s1[i]; if c='/'then begin ss1:=copy(s1,1,i-1); delete(s1,1,i); ss2:=s1; val(ss1,x1,code); val(ss2,x2,code); break; end; end; for i:=1 to length(s2)do begin c:=s2[i]; if c='/'then begin ss1:=copy(s2,1,i-1); delete(s2,1,i); ss2:=s2; val(ss1,y1,code); val(ss2,y2,code); end; end; if jl=1 then begin op1:=x1*y2+x2*y1; op2:=x2*y2; op3:=zdgys(op1,op2); if (op2 div op3<>1)and(op1 div op3<>0)then writeln(op1 div op3,'/',op2 div op3) else if op2 div op3=1 then writeln(op1 div op3) else if op1 div op3=0 then writeln(0); end else if jl=2 then begin op1:=x1*y2-x2*y1; op2:=x2*y2; op3:=zdgys(op1,op2); if (op2 div op3<>1)and(op1 div op3<>0)then writeln(op1 div op3,'/',op2 div op3) else if op2 div op3=1 then writeln(op1 div op3) else if op1 div op3=0 then writeln(0); end; end; begin readln(s); while s<>'' do begin jl:=0; main; readln(s); end; end; begin init; end. Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator