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

看看我这个,怎么AC不了,测试都OK

Posted by jackch at 2006-09-12 14:54:52 on Problem 1930
#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:
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