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 SLAMDUNK2008 at 2008-08-21 16:31:13 on Problem 1019
//import java.io.*;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		//DataInputStream dis=new DataInputStream(System.in);
		Scanner sin = new Scanner(System.in);
		int t=sin.nextInt();
		int[] state=new int[t];
		StringBuffer sb=new StringBuffer();
		//sb.append(1);
		for(int i=0;i<t;i++){
				int sum=0;
				state[i]=sin.nextInt();
				int j=1;
				int len=0;
				while(sum<state[i]){
					 len=j;
					/*for(int k=1;k<=j;k++){
						String str=String.valueOf(k);
						len=len+str.length();
					}*/
					 if(j>=10){
						 len=len+j-9;
						 if(j>=100){
							 len=len+j-99;
							 if(j>=1000){
								 len=len+j-999;
								 if(j>=10000){
									 len=len+j-9999;
									 if(j>=100000){
										 len=len+j-99999;
										 if(j>=1000000){
											 len=len+j-999999;
											 if(j>=10000000){
												 len=len+j-9999999;
												 if(j>=100000000){
													 len=len+j-99999999;
												 }
											 }
										 }
									 }
								 }
							 }
						 }
					 }
					sum=sum+len;
					j++;
				}
				j--;
				sum=state[i]-sum+len;
				for(int k=1;k<=j;k++){
					sb.append(k);
				}
				System.out.println(sb.charAt(sum-1));
				sb=null;
				sb=new StringBuffer();
		}
	}

}

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