标签:des style blog color io os ar java for
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 6669 | Accepted: 3641 |
Description
Input
Output
Sample Input
0.75 0.0001 0.01234567
Sample Output
0.75 [8] = 0.953125 [10] 0.0001 [8] = 0.000244140625 [10] 0.01234567 [8] = 0.020408093929290771484375 [10]
用java的大数,感觉挺好
import java.util.*; import java.io.*; import java.math.*; import java.text.*; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(new BufferedInputStream(System.in)); ///用BufferedInputStream据说能快点 BigDecimal ans, t, tmp; while(sc.hasNext()){ String st = sc.nextLine(); ///字符串输入 t = BigDecimal.valueOf(1); ans = BigDecimal.valueOf(0); int i, sta = st.indexOf(‘.‘);//找到第一次出现‘.‘ 的位置 for(i = sta+1; i < st.length(); ++i){ ///获取字符串长度只能用length()方法 tmp = BigDecimal.valueOf(st.charAt(i) - ‘0‘); //charAt()获取当前位置的字符 t = t.divide(new BigDecimal("8")); //大数只能和大数进行运算,Int只能与Int String只能和String tmp = tmp.multiply(t);//乘 ans = ans.add(tmp);//加 } System.out.println(st + " [8] = " + ans + " [10]"); ///也可用System.out.printf(); } } }
标签:des style blog color io os ar java for
原文地址:http://www.cnblogs.com/ya-cpp/p/4025576.html