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

            四虎国产精品免费久久5151 | 久久国产乱子伦精品免费午夜| 精品一二三区久久aaa片| 中文字幕日本人妻久久久免费| 精品久久久久久中文字幕人妻最新| 久久精品国产99国产精品澳门| 99热热久久这里只有精品68| 久久久这里只有精品加勒比| A级毛片无码久久精品免费| 久久99热只有频精品8| 久久精品亚洲男人的天堂| 久久精品天天中文字幕人妻| 久久成人永久免费播放| 国产∨亚洲V天堂无码久久久| 久久久久一本毛久久久| 国内精品久久久久久99蜜桃| 午夜精品久久久内射近拍高清 | 99久久精品国产毛片| 丁香色欲久久久久久综合网| 国产精品伊人久久伊人电影| 久久精品黄AA片一区二区三区| 久久精品国产黑森林| 日本免费一区二区久久人人澡 | 久久亚洲国产中v天仙www | 久久久久久精品成人免费图片| 品成人欧美大片久久国产欧美| 亚洲精品白浆高清久久久久久| 欧美麻豆久久久久久中文| 久久免费国产精品一区二区| 精品国产VA久久久久久久冰| 久久人人爽人人爽人人片av麻烦| 精品国产综合区久久久久久 | 久久人人爽人人爽人人AV东京热| 久久久午夜精品福利内容| 久久久WWW免费人成精品| 亚洲一本综合久久| 日本久久久久久中文字幕| 久久99国产一区二区三区| 情人伊人久久综合亚洲| 品成人欧美大片久久国产欧美| 久久伊人精品青青草原高清|