• <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 閱讀(634) 評(píng)論(0)  編輯 收藏 引用 所屬分類: Algorithm

            一本大道加勒比久久综合| 狠狠人妻久久久久久综合蜜桃| 久久综合综合久久狠狠狠97色88| 久久久一本精品99久久精品88| 94久久国产乱子伦精品免费| 久久ZYZ资源站无码中文动漫| 狠狠色丁香久久婷婷综合| 久久久高清免费视频| A级毛片无码久久精品免费| 人人狠狠综合久久亚洲88| 激情伊人五月天久久综合| 91精品国产综合久久婷婷| 久久九九精品99国产精品| 久久人爽人人爽人人片AV| 日本久久久久亚洲中字幕| 色欲久久久天天天综合网精品 | 精品久久久无码中文字幕天天| av无码久久久久不卡免费网站| 久久精品黄AA片一区二区三区| 久久99精品国产自在现线小黄鸭 | 亚洲乱码精品久久久久..| 一本一本久久a久久综合精品蜜桃| 久久久久久久波多野结衣高潮 | 久久精品国产99久久香蕉| 日日狠狠久久偷偷色综合免费| 中文字幕精品无码久久久久久3D日动漫 | 国产成人精品久久一区二区三区| 亚洲综合熟女久久久30p| 欧美喷潮久久久XXXXx| 久久av无码专区亚洲av桃花岛| 久久久国产精品网站| 久久噜噜久久久精品66| 精品国产日韩久久亚洲| AV狠狠色丁香婷婷综合久久 | 无码任你躁久久久久久久| 久久91精品国产91久| 国产成人久久精品激情| 日韩电影久久久被窝网| 狠狠狠色丁香婷婷综合久久俺| 久久久久成人精品无码| MM131亚洲国产美女久久|