| ||||||||||
| 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 | |||||||||
The test data is perfectly OK, ^_^In Reply To:Re:Is the test data OK? Posted by:javaman at 2005-08-26 09:18:28 > #include <iostream>
> #include <cstdio>
> #include <cmath>
> #include <string>
>
> using namespace std;
>
> typedef __int64 ll;
>
> char s[100];
>
> ll gcd(ll a,ll b) {
> return b?gcd(b,a%b):a;
> }
>
> int main() {
> ll a,b,c,d,p,q,g,x,bestp,bestq;
> int bit,i;
>
> while (true) {
> scanf("%s",s);
> if (!strcmp(s,"0"))
> break;
> bit=strlen(s)-5;
> s[bit+2]=0;
> sscanf(s+2,"%I64d",&x);
> bestq=-1;
> for (i=1;i<=bit;++i) {
> p=(ll) pow(10.,(double) (bit-i));
> q=(ll) pow(10.,(double) i);
> a=x/q;
> c=x%q;
> b=p;
> d=(q-1)*p;
> g=gcd(a,b);
> a/=g;
> b/=g;
> g=gcd(c,d);
> c/=g;
> d/=g;
> p=a*d+b*c;
> q=b*d;
> g=gcd(p,q);
> p/=g;
> q/=g;
> if ((bestq<0) || (bestq>q) || ((bestq==q) && (bestp<p))) {
> bestp=p;
> bestq=q;
> }
> }
> printf("%I64d/%I64d\n",bestp,bestq);
> }
> return 0;
> }
>
>
>
>
>
>
>
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator