import java.math.BigDecimal; import java.io.*; import java.math.*; import java.util.*; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub String str; Scanner cin = new Scanner( new BufferedInputStream( System.in ) ); while( cin.hasNext() ){ str = cin.nextLine(); BigDecimal bas = new BigDecimal( 8 ); BigDecimal ans = new BigDecimal( 0 ); BigDecimal temp = new BigDecimal( 1 ), t; for( int i = 2; i < str.length(); ++i ){ temp = temp.divide( bas ); ans = ans.add( new BigDecimal( str.charAt( i ) - ‘0‘ ).multiply( temp ) ); } System.out.println(str + " [8] = " + ans.stripTrailingZeros().toPlainString() + " [10]"); } } }
Octal Fractions
http://poj.org/problem?id=1131