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 sophia_philem at 2005-10-04 01:48:03 on Problem 1019
//////sophia_philem
#include<iostream>
#include<cmath>
using namespace std;
unsigned long int length(unsigned long int k)
{
	unsigned long int n= int(log10(k))+1;
	unsigned long int len=0;
	for(unsigned long int i=2;i<=n;i++)
	{
		len += 9 * unsigned long int( pow(10,i-2) )*(i-1);
	}
	len+=( k- unsigned long int(pow(10,n-1))+1 )*n;
	return len;
}
unsigned long int leng(unsigned long int k )
{
	unsigned long int len=0;
	
		len=pow(10,k)-1;
	return len;
}
long int main()
{
	
	unsigned long int t;
	cin>>t;
	while( t > 0 )
	{
		t--;
		unsigned long int i;
		cin>>i;
		for(unsigned long int j=1;;)
			if( i > length(j) )
			{
				i-=length(j);
				j++;
			}
			else
				if( i== length(j))
				{	break;   }
				else if( i < length (j)  )
				{    break;}
		cout<<"j="<<j<<"i="<<i<<endl;	
		//s(j)组中 ;
		for(unsigned long int k=1; ; )
			if(i > leng(k) )   k++;
			else if(i == leng(k)){ i = i-leng(k-1);break;}
			else if( i< leng(k) )
			{
				i = i- leng(k-1); break;
			}
		unsigned long int n=k;//n位数;
		cout<<n<<"位数"<<"  i="<<i<<endl;
		//////////
		for(unsigned long int l=1 ; ; )
			if(i> l * n ) l++;
			else if(i == l*n) { i=i - (l-1)*n; break;}
			else if(i < l*n) { i= i- (l-1)*n; break;}
		//n位数中第l个;
		cout<<n<<"位数中第"<<l<<"个   i="<<i<<endl;
		unsigned long int p= unsigned long(pow( 10, n-1)) + l-1;//目标数;
		cout<<"目标数="<<p<<endl;
		unsigned long int q=0;
		while(q < n - i )
		{
			p=p/10;
			q++;
		}
		unsigned int res = p%10;
		cout<<res<<endl;
	
	}
	return 0;
}

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