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

Re:我用了字符串的方法,有更高效的方法吗??

Posted by kingover at 2008-08-20 17:34:03 on Problem 1019
In Reply To:我用了字符串的方法,有更高效的方法吗?? Posted by:church at 2007-05-20 11:28:50
> #include <iostream.h>
> #include <stdlib.h>
> #include <string.h>
> 
> void main()
> {
>     long i,j,k,m,n,sum;
> 	char a[10];
> 	int radix=10;
> 
> 	cin>>m;
> 	for(i=0;i<m;i++)
> 	{
> 		cin>>n;
> 		k=1; sum=1;
> 		while (n>sum)
> 		{
> 			n=n-sum;
> 			k++;
> 			ltoa(k,a,radix);
> 			sum=sum+strlen(a);
> 		}
> 		j=1; sum=1;
> 		ltoa(j,a,radix);
> 		while (n>sum)
> 		{
> 			n=n-sum;
> 			j++;
> 			ltoa(j,a,radix);
> 			sum=strlen(a);
> 		}
> 		n--;
> 		cout<<a[n]<<endl;
> 	}
> }

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