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

            久久久久久A亚洲欧洲AV冫| 亚洲人成网亚洲欧洲无码久久| 久久国产乱子伦免费精品| 国产成人综合久久综合| 99久久99久久精品国产片| 一级女性全黄久久生活片免费| 亚洲国产精品一区二区久久hs| 99久久精品费精品国产一区二区| 99久久精品免费观看国产| 一本色道久久综合狠狠躁| 草草久久久无码国产专区| 亚洲AV无码成人网站久久精品大| 久久午夜伦鲁片免费无码| 久久综合精品国产一区二区三区| 久久婷婷五月综合国产尤物app| 久久久WWW成人免费毛片| 国产一级做a爰片久久毛片| 怡红院日本一道日本久久| 亚洲伊人久久综合中文成人网| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 国产日韩欧美久久| 无码人妻少妇久久中文字幕蜜桃| 久久久久久A亚洲欧洲AV冫 | 久久狠狠爱亚洲综合影院| 国产成人精品久久亚洲高清不卡| 久久久亚洲欧洲日产国码aⅴ| 亚洲人成无码网站久久99热国产| 国产高清美女一级a毛片久久w| 精品久久久久久无码专区不卡| 久久精品国产亚洲AV香蕉| 久久婷婷是五月综合色狠狠| 久久久久久A亚洲欧洲AV冫| 国产高潮久久免费观看| 久久综合欧美成人| 91精品日韩人妻无码久久不卡| 久久婷婷久久一区二区三区| 久久99热狠狠色精品一区| 亚洲一本综合久久| 久久电影网| 性做久久久久久久久浪潮| 无码久久精品国产亚洲Av影片|