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;
    }

  • 相关阅读:
    jQuery学习笔记
    MAMP的使用
    svn使用
    Docker 下安装 MySQL时,docker-compose.yml 的写法
    MySQL 8报错:The user specified as a definer ('mysql.infoschema'@'localhost') does not exist
    Zookeeper 总结及安装
    Docker 在 Linux 下的安装与配置
    Linux更换国内软件源
    gitlab-runner一直处于挂起/pedding状态
    GitLab出现forbidden的解决方法
  • 原文地址:https://www.cnblogs.com/xin-hua/p/3211725.html
Copyright © 2011-2022 走看看