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求助____________狂RE,是输入问题么...

Posted by majia6 at 2008-08-09 14:47:43 on Problem 1001
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String args[]) throws Exception
    {
       String s,res,temp;
       Scanner in=new Scanner(System.in);
       int i,j,k,value;
       boolean flag,is;
       while((s=in.next())!=null)
       {
    	  i=in.nextInt();
    	  value=0;
    	  flag=false;
    	   BigDecimal a=new BigDecimal(s.trim());
    	   res=a.pow(i).toPlainString();
    	   for(j=0;j<res.length();j++)
    	   {
    		   if(res.charAt(j)!='.')
    			   value=value*10+res.charAt(j)-'0';
    		   else
    		   {
    			   flag=true;
    			   if(value!=0)
    				   {
    				   	temp=res.substring(0, j);
    				   	System.out.print(temp);
    				   }
    			   break;
    		   }
    	   }
    	   if(flag)
    	   {
    		 is=false;
    	     temp=res.substring(j+1);
    	     for(k=0;k<temp.length();k++)
    	    	 if(temp.charAt(k)!='0')
    	    		 {is=true;break;}
    	     if(is)
    	    	 {
    	    	 	System.out.print('.');
    	    	 	for(k=temp.length()-1;k>=0;k--)
    	    	 	{
    	    	 		if(temp.charAt(k)!='0')break;
    	    	 	}
    	    	 	System.out.println(temp.substring(0,k+1));
    	    	 }
    	   }
    	   else
    		   System.out.println(res);
       }
    }
}

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