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

为啥我的c++ ac了,G++就wa了类,大牛帮忙看看啊,附代码

Posted by anlan at 2009-08-10 13:57:46 on Problem 1019
#include<stdio.h>
long p=1,n[200001]={0,1},sum[300001]={0,1};
int weishu(long m)
{
	int num=0;
	while(m>0)
	{
		num++;
		m=m/10;
	}
	return num;
}

int main()
{
	int t=0;
	long long i,j=2,k;
	for(i=2;i<=300000&&sum[i-1]>=0;i++)
	{
		t=weishu(i);
		j=i;
		for(k=t;k>=1;k--)
		{
			n[p+k]=j%10;
			j/=10;
		}
		p=p+t;
		sum[i]=sum[i-1]+p;
	}
	scanf("%d",&t);
	while(t--)
	{
		scanf("%lld",&j);
		for(k=0;k<i-1;k++)
		{
			if(sum[k]>=j)
			{
				j=j-sum[k-1];
				break;
			}
		}
		if(k==i-1)j=j-sum[i-2];
		printf("%lld\n",n[j]);
	}
	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