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

            大香伊人久久精品一区二区| 色综合久久天天综合| 久久99这里只有精品国产| 久久伊人亚洲AV无码网站| 久久亚洲AV成人无码软件| 色偷偷88888欧美精品久久久| 久久精品aⅴ无码中文字字幕重口| 日韩一区二区久久久久久| 亚洲精品WWW久久久久久| 91精品国产9l久久久久| 久久露脸国产精品| 国产精品女同久久久久电影院| 精品无码人妻久久久久久| 蜜臀av性久久久久蜜臀aⅴ| 精品久久综合1区2区3区激情| 国产成人久久精品一区二区三区| 久久午夜电影网| 亚洲人成精品久久久久| 久久伊人中文无码| 精品久久久久久中文字幕| 久久久久久精品久久久久| 久久综合九色综合久99| 久久91精品久久91综合| 亚洲精品乱码久久久久久蜜桃图片 | 7777精品伊人久久久大香线蕉| 久久久精品人妻一区二区三区四| 久久成人精品| 久久99精品国产| 久久亚洲中文字幕精品有坂深雪| 亚洲欧美日韩精品久久亚洲区 | 久久这里只精品国产99热 | 99久久婷婷免费国产综合精品| 久久婷婷五月综合97色直播| 国产免费久久精品丫丫| 国产福利电影一区二区三区,免费久久久久久久精 | 久久久中文字幕日本| 免费国产99久久久香蕉| 青青草原综合久久大伊人精品| 国产成人久久精品一区二区三区 | 人妻精品久久久久中文字幕69| 久久人人添人人爽添人人片牛牛|