Octal Fractions Java sec C + +

Source: Internet
Author: User

                           Octal Fractions

Abstract: Convert octal decimals to decimal small trees. The number of decimals is very large.

You can use Bigdeciaml seconds in Java to drop. Time:297ms

1 Importjava.math.*;2 ImportJava.util.*;3 ImportJava.io.*;4 Importjava.text.*;5 6  Public classMain7 {8     Static intms=3005;9      Public Static voidMain (string[] args)Ten     { OneScanner cin=NewScanner (NewBufferedinputstream (system.in)); A          while(Cin.hasnext ()) -         { -String str=Cin.next (); theBigDecimal sum=NewBigDecimal (0); -BigDecimal tmp=NewBigDecimal (1); -BigDecimal eight=NewBigDecimal (8); -              for(intI=2;i<str.length (); i++) +             { -tmp=Tmp.divide (eight); +Sum=sum.add (Tmp.multiply (NewBigDecimal (Str.charat (i)-' 0 ') ));  A             } atSYSTEM.OUT.PRINTLN (str + "[8] =" + sum.tostring () + "[10]"); -         } - cin.close (); -     } -}

C + + time:0ms

1#include <iostream>2#include <string.h>3#include <cstdio>4 using namespacestd;5 Const intms=1001;6 7 intMain ()8 {9     Charstr[ms],ans[3*MS];Ten     intI,j,index,num; One      while(SCANF ("%s", str)! =EOF) A     { -         intlen=strlen (str); -index=0; thememset (ans,0,sizeof(ans)); -          for(i=len-1;i>1; i--) -         { -num=str[i]-'0'; +              for(j=0; j<index| | num;j++) -             { +num=num*Ten+ (j<index?ans[j]-'0':0); Aans[j]=num/8+'0'; atnum=num%8; -             } -index=J; -         } -printf"%s [8] = 0.%s [10]\n", Str,ans); -     } in     return 0; -}

Octal Fractions Java sec C + +

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.