| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
Re:为什么老是WA啊,本机完全可以通过.In Reply To:为什么老是WA啊,本机完全可以通过. Posted by:susu at 2004-10-12 16:08:15 > import java.io.*;
> import java.util.*;
> import java.math.*;
>
> class Exponentiation
> {
> public static void main(String[] args) throws Exception
> {
> BufferedReader stdin = new BufferedReader(
> new InputStreamReader(System.in));
>
> String line;
>
> while ((line = stdin.readLine()) != null)
> {
> StringTokenizer st = new StringTokenizer(line);
> BigDecimal v = new BigDecimal(st.nextToken());
> BigDecimal res = new BigDecimal("1");
> int n = Integer.parseInt(st.nextToken());
>
> while (n > 0)
> {
> res = res.multiply(v);
> n--;
> }
>
> print(res.toString());
>
> }
> }
> private static void print(String s) throws Exception
> {
> int begin, e,end;
> begin = 0;
> end = s.length();
> e = end;
>
> while ((e > 0) && (s.charAt(e - 1) != 'E') )
> {
> e--;
> }
>
>
> while ((end > 0) && (s.charAt(end - 1) == '0'))
> {
> end--;
> }
> if (e == 0)
> {
> System.out.println(s.substring(0, end));
> }
> else
> {
> int en = Integer.parseInt(s.substring(e+1, s.length()));
> String ps = ".";
> int j = en;
> while ((--j) >0)
> {
> ps += '0';
> }
> ps = ps + s.substring(0,e-1);
> int i = en + 1;
> while ((i < ps.length()) && (ps.charAt(i) != '.') )
> {
> i++;
> }
> if (i != ps.length())
> {
> ps = ps.substring(0, i) + ps.substring(i+1);
> }
> System.out.println(ps);
> }
>
> }
> }
>
> Memory Cost居然是1.75KB,看来我得优化一下.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator