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测试都对,为什么wa啊

Posted by n55iw at 2011-07-23 15:04:30 on Problem 1565
import java.util.*;
import java.math.BigInteger;
public class Main{
	static int p(int w,int e)
	{
		int s=1,q;
		for(q=0;q<e;q++) s*=w;
		return s;

	}
	public static void main(String[] args) {
	     Scanner cin=new Scanner(System.in);
	     String n;
	     while(cin.hasNext())
	     {
	    	 n=cin.nextLine();
	    	 int l=n.length();
	    	 if(l==1) {if(Integer.valueOf(n)==0)System.exit(0);}
	    	 else
	    	 {
	    	
	    	 BigInteger sum=new BigInteger("0");
	    	
	    	 for(int j=0;j<l;j++)
	 		{   int r=(int)n.charAt(j)-'0';
	 		    int x=r*(p(2,l-j)-1);
	 			sum=sum.add(new BigInteger(Integer.toString(x)));
	 		}
	    	 System.out.println(sum);}
	     }
	}

}

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