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

Java 太帅了!!!

Posted by javawin at 2011-05-20 20:36:01 on Problem 1001
import java.math.BigDecimal;
import java.util.Scanner;
public class Main { 
    public static void main(String[] args) {
        BigDecimal s;
        int n;
        Scanner cin=new Scanner(System.in);
        while(cin.hasNextBigDecimal()){
            s=cin.nextBigDecimal();
            n=cin.nextInt();
            //System.out.println(s.pow(n));
            BigDecimal ans=s.pow(n);
             String src=ans.toPlainString(); 
            int i=0;
             int j=src.length();
            if(src.indexOf('.')!=-1){
              if(src.charAt(0)=='0'){
                  i=1;
              }
              for( j=src.length()-1;j>=0;j--){
                  if(src.charAt(j)=='0')continue;
                  break;
              }
              j++;
            }
             if(src.charAt(j-1)=='.'){
                 j--;
             }

            System.out.println(src.substring(i,j));
        }
    }

}

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