zoukankan      html  css  js  c++  java
  • hdu 1905 小数化分数2

    #include<iostream>
    #include<stdio.h>
    #include<algorithm>
    #include<iomanip>
    #include<cmath>
    #include<cstring>
    #include<vector>
    #include<stdlib.h>
    #define ll __int64
    #define pi acos(-1.0)
    using namespace std;
    int
    gcd(int a,int b)
    {

        int
    t;
        if
    (a<b) swap(a,b);
        while
    (b)
        {

            t=a;
            a=b;
            b=t%b;
        }

        return
    a;
    }

    int
    pows(int n)
    {

        int
    ans=1;
        while
    (n--)
            ans*=10;
        return
    ans;
    }

    int
    main()
    {

        int
    i,j,n,sum,t,pos1,pos2,pos3,a,b,c,len;
        string an;
        cin>>t;
        while
    (t--)
        {

            cin>>an;
            len=an.length();
            pos2=an.find('(',0);
            pos3=an.find(')',pos2);
            if
    (pos2<0)
            {

                a=0;
                for
    (i=2;i<len;i++)
                    a=a*10+an[i]-'0';
                b=pows(len-2);
            }

            else

            {

                a=0;
                for
    (i=2;i<pos2;i++)
                    a=a*10+an[i]-'0';
                c=0;
                for
    (i=pos2+1;i<pos3;i++)
                    c=c*10+an[i]-'0';
                b=pows(pos3-pos2-1);
                sum=a*b+c;
                a=sum-a;
                b=(b-1)*pows(pos2-2);
            }

            c=gcd(a,b);
            cout<<a/c<<'/'<<b/c<<endl;
        }

        return
    0;
    }

  • 相关阅读:
    MVC3 中上传大文件
    js 将十进制转换为八位二进制数组
    nodejs 读取并处理二进制文件
    freeswitch源码编译 ./configure 遇到的问题
    通道设置静态坐席
    呼叫中心静态座席的配置
    ECharts报表
    combotree
    openlayer PanZoom
    为什么要始终使用PreparedStatement代替Statement?
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3211725.html
Copyright © 2011-2022 走看看