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

why WA!!

Posted by niyuzhe at 2007-05-02 18:11:49 on Problem 1019
#include<iostream>
using namespace std;

int main()
{
	int t;
	int num[4]={45,9000,1386450,188019000};
	int dig[4]={1,11,192,2893};
	int dig2[5]={9,180,2700,36000,450000};
	cin>>t;
	//t=1;
	while(t--)
	{
		long int n;//=t;
		cin>>n;
		int i;
		for(i=0;i<=3&&n-num[i]>0;i++)
		{
			n-=num[i];
		}
		i++;
		int d=dig[i-1];
		while(n-d>0)
		{
			n-=d;
			d+=i;
		}//now the answer is the nth digit of the number sequence 123456789101112...
		int a;
		for(a=0;n-dig2[a]>0;a++)
		{
			n-=dig2[a];
		}
		a++;
		//now the answer is the nth number of the number sequence (10^(a-1) 10^(a-1)+1 10^(a-1)+2 ...)
		int b=(n+a-1)%a;
		int c=(n+a-1)/a;
		//now the answer is the bth number of the number 10^(a-1)+c-1
		int num=1;
		for(int p=0;p<a-1;p++)
		{
			num*=10;
		}
		num+=(c-1);
		for(int q=0;q<a-b-1;q++)
		{
			num/=10;
		}
		cout<<(num-num/10*10)<<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