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 |
看看我这个,怎么AC不了,测试都OK#include<iostream> #include<string.h> #include<math.h> using namespace std; int gcd(long a,long b) { return b?gcd(b,a%b):a; } int main() { char str[20]; long mu,zi,mu1,zi1,mu2,zi2,a; int c; cin>>str; while(strcmp(str,"0")!=0) { mu1=1; zi1=0; char *p=&str[2]; while(*p!='.') p++; p--; c=*p-48; while(*p==c+'0') p--; char *q=&str[2]; while(q<=p) {zi1=10*zi1+*q-'0';mu1*=10;q++;} if(c!=9) {zi2=c; mu2=9*mu1; mu=mu2; zi=zi1*9+zi2; } else {zi2=1;mu2=mu1;mu=mu2;zi=zi2+zi1;} a=gcd(mu,zi); cout<<zi/a<<"/"<<mu/a<<endl; cin>>str; } getchar(); return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator