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 |
所有的数据都对,为何WA????#include<iostream> using namespace std; struct FS { int fz; int fm; }; int gcd(int a, int b) { if(a<b) { int temp=a; a=b; b=temp; } if(b==0) return a; else return gcd(b,a%b); } int main() { int a,b; int c,d; char ch1,ch2,ch; int g; while(cin>>a>>ch1>>b>>ch>>c>>ch2>>d) { FS fs1; FS fs2; FS fs; fs1.fz=a; fs1.fm=b; fs2.fz=c; fs2.fm=d; switch(ch) { case'+': { fs.fz=fs1.fz*fs2.fm+fs1.fm*fs2.fz; fs.fm=fs1.fm*fs2.fm; break; } default: { fs.fz=fs1.fz*fs2.fm-fs1.fm*fs2.fz; fs.fm=fs1.fm*fs2.fm; break; } } if(!fs.fz) { cout<<fs.fz/fs.fm<<endl; } if(fs.fz!=fs.fm && fs.fz>0) { g=gcd(fs.fz,fs.fm); fs.fz/=g; fs.fm/=g; cout<<fs.fz<<"/"<<fs.fm<<endl; } if(fs.fz!=fs.fm && fs.fz<0) { g=gcd(-fs.fz,fs.fm); fs.fz/=g; fs.fm/=g; cout<<fs.fz<<"/"<<fs.fm<<endl; } if(fs.fz==fs.fm) { cout<<fs.fz/fs.fm<<endl; } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator