Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

实在是没招了,大拿们帮忙看看吧!!!!!

Posted by sza at 2006-03-30 11:21:09 on Problem 1001
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String args[]) throws Exception {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.
                in));
        String string;
        StringTokenizer st;
        BigDecimal p;
        BigDecimal result;
        int n;
        while (true) {
            result = new BigDecimal("1");
            string = stdin.readLine();
            if (string == null) {
                break;
            }
            st = new StringTokenizer(string);

            String temStr = st.nextToken();
            p = new BigDecimal(temStr);
            n = Integer.parseInt(st.nextToken());
            for (int i = 0; i < n; i++) {
                result = result.multiply(p);
            }
            String tem = result.toString();
            int start = 0, end = tem.length() - 1;
            while (start<tem.length()&&tem.charAt(start) == '0') {
                start++;
            }
            int ends=0;
            while(ends<tem.length() && tem.charAt(ends)!='.') ends++;
            while (end>ends&&tem.charAt(end) == '0') {
                end--;
            }
            if (tem.substring(start, end + 1).equals("0")||tem.substring(start, end + 1).equals("")) {
                System.out.println(".");
            } else {
                System.out.println(tem.substring(start, end + 1));
            }
        }
    }
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator