• <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

            基礎知識學習
            隨筆 - 4, 文章 - 0, 評論 - 0, 引用 - 0
            數據加載中……

            java 分數類

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

            精品久久久久中文字| 女人香蕉久久**毛片精品| 很黄很污的网站久久mimi色| 99久久婷婷免费国产综合精品| 日韩精品久久久久久久电影蜜臀| 囯产精品久久久久久久久蜜桃 | 亚洲国产成人精品无码久久久久久综合| 77777亚洲午夜久久多喷| 99久久中文字幕| 99久久99久久精品国产片果冻| 国产成人无码久久久精品一 | 久久99精品国产一区二区三区| 狠狠精品久久久无码中文字幕| 久久九九兔免费精品6| 国产精品视频久久久| 狠狠色丁香久久婷婷综合蜜芽五月| 久久影院综合精品| 久久超乳爆乳中文字幕| 久久综合久久鬼色| www.久久精品| 久久久免费观成人影院| 77777亚洲午夜久久多喷| 久久久久久毛片免费看| 国产精品久久久久久久久免费 | 婷婷综合久久狠狠色99h| 久久强奷乱码老熟女网站 | 久久精品国产一区二区三区| 国产午夜久久影院| 国产三级久久久精品麻豆三级| 午夜精品久久久久久中宇| 亚洲精品WWW久久久久久| 久久高潮一级毛片免费| 色综合久久中文色婷婷| 亚洲精品高清久久| 一本一道久久精品综合| 99久久超碰中文字幕伊人| 国产精品对白刺激久久久| 久久精品国产亚洲AV大全| 97r久久精品国产99国产精| 日韩精品久久久久久久电影蜜臀| 亚洲欧美日韩久久精品第一区|