• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Try Again

            基礎(chǔ)知識(shí)學(xué)習(xí)
            隨筆 - 4, 文章 - 0, 評(píng)論 - 0, 引用 - 0
            數(shù)據(jù)加載中……

            java 分?jǐn)?shù)類

            class Fraction
            {
                BigInteger up, down;
                
            public Fraction (Fraction f)
                {
                    
            this.up = f.up;
                    
            this.down = f.down;
                }
                
            public Fraction(String s)
                {
                    
            this.up = new BigInteger(s);
                    
            this.down = new BigInteger("1");
                }
                
            public Fraction(BigInteger a, BigInteger b)
                {
                    
            this.up = a;
                    
            this.down = b;
                }
                
            public BigInteger getUp()
                {
                    
            return this.up;
                }
                
            public BigInteger getDown()
                {
                    
            return this.down;
                }
                
            public Fraction subtract(Fraction f)
                {
                    BigInteger save1 
            = this.up.multiply (f.down);
                    BigInteger save2 
            = f.up.multiply(this.down);
                    Fraction tmp 
            = new Fraction(save1.subtract (save2), f.down .multiply ( this.down));
                    
            return simplex(tmp);
                }
                
            public Fraction add(Fraction f)
                {
                    Fraction tmp 
            = new Fraction ("0");
                    tmp 
            = tmp.subtract(f);
                    Fraction ans 
            = new Fraction (this.subtract(tmp));
                    
            return ans;
                }
                
            public Fraction multiply(Fraction f)
                {
                    Fraction tmp;
                    tmp 
            = new Fraction(this.up.multiply (f.up), this.down.multiply (f.down));
                    
            if (tmp.down.compareTo(new BigInteger("0")) == -1)
                    {
                        tmp.down 
            = tmp.down.multiply (new BigInteger("-1"));
                        tmp.up 
            = tmp.up.multiply (new BigInteger("-1"));
                    }
                    
            return simplex(tmp);
                }
                
            public Fraction divide(Fraction f)
                {
                    Fraction tmp 
            = null;
                    tmp 
            = new Fraction(this.up.multiply (f.down), this.down.multiply (f.up));
                    
            if (tmp.down.compareTo(new BigInteger("0")) == -1)
                    {
                        tmp.down 
            = tmp.down.multiply (new BigInteger("-1"));
                        tmp.up 
            = tmp.up.multiply (new BigInteger("-1"));
                    }
                    
            return simplex(tmp);
                }
                BigInteger gcd(BigInteger a, BigInteger b)
                {
                    
            if (b.compareTo(new BigInteger("0")) == 0)
                        
            return a;
                    
            return gcd(b, a.remainder (b));
                }
                Fraction simplex(Fraction f)
                {
                    BigInteger tmp 
            = gcd(f.up.abs(), f.down.abs ());
                    f.up 
            = f.up.divide (tmp);
                    f.down 
            = f.down.divide (tmp);
                    
            return f;
                }
                
            void print()
                {
                    BigInteger a, b, c;
                    a 
            = this.getUp ();
                    b 
            = this.getDown();
                    c 
            = gcd(a.abs(), b.abs());
                    a 
            = a.divide (c);
                    b 
            = b.divide (c);
                    
            if (b.compareTo (new BigInteger("1")) == 0)
                        System.out.println(a);
                    
            else
                        System.out.println (a 
            + "/" + b);
                }
            }

            posted on 2009-03-08 21:02 NicYun 閱讀(631) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Algorithm

            无码人妻久久久一区二区三区| 99久久无色码中文字幕人妻| 国产精品青草久久久久婷婷| 精品国产一区二区三区久久| 日韩精品久久久久久| 久久久久久一区国产精品| 亚洲国产欧美国产综合久久| 国产精品久久久久久一区二区三区| 91亚洲国产成人久久精品| 久久久国产打桩机| 久久se精品一区精品二区| 国产高清美女一级a毛片久久w| 欧美久久久久久| 国内精品久久久久久久影视麻豆| 精品伊人久久久| 久久激情亚洲精品无码?V| 国产精品9999久久久久| 色综合久久久久综合99| 久久亚洲国产午夜精品理论片| 97久久国产露脸精品国产| 久久久久亚洲AV成人网| 精品一区二区久久久久久久网站| 中文字幕亚洲综合久久菠萝蜜| 丁香久久婷婷国产午夜视频| 欧美亚洲国产精品久久| 亚洲国产成人久久综合碰碰动漫3d | 久久e热在这里只有国产中文精品99| 蜜桃麻豆WWW久久囤产精品| 国产成人AV综合久久| 国产精品禁18久久久夂久| 午夜精品久久久久久久| 久久精品日日躁夜夜躁欧美| 久久综合五月丁香久久激情| 国产精品亚洲综合专区片高清久久久| 国产精品99久久免费观看| 国产精品久久久久…| 欧美亚洲国产精品久久蜜芽| 久久久久综合网久久| 国产视频久久| 久久精品无码一区二区日韩AV| 久久久精品无码专区不卡|