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

            国产成人无码久久久精品一 | 人妻无码αv中文字幕久久琪琪布| 蜜桃麻豆www久久国产精品| 久久久无码精品午夜| 日本强好片久久久久久AAA| 久久精品成人国产午夜| 久久久久久久综合狠狠综合| 久久青青草原精品国产| 午夜精品久久影院蜜桃| 99久久无码一区人妻a黑| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久精品99无色码中文字幕| 综合久久一区二区三区 | 久久强奷乱码老熟女网站| 色综合久久综合网观看| 亚洲欧美日韩中文久久| 亚洲AV伊人久久青青草原| 97久久婷婷五月综合色d啪蜜芽| 精品无码久久久久国产| 久久精品国产亚洲AV香蕉| 亚洲国产精品嫩草影院久久| 国产2021久久精品| 久久久国产精品福利免费| 99久久99久久| 久久91精品国产91久久小草| 久久精品蜜芽亚洲国产AV| 色偷偷偷久久伊人大杳蕉| 亚洲狠狠婷婷综合久久久久 | 狠狠88综合久久久久综合网| 久久亚洲AV无码精品色午夜 | 中文字幕无码久久人妻| 久久亚洲欧洲国产综合| 欧美亚洲日本久久精品| 久久乐国产精品亚洲综合| 无夜精品久久久久久| 超级97碰碰碰碰久久久久最新| 亚洲午夜精品久久久久久浪潮| 日韩中文久久| 亚洲精品白浆高清久久久久久| 久久精品人人槡人妻人人玩AV | 久久强奷乱码老熟女网站|