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