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

无需用long int足以解决 贴0MS代码

Posted by xuchang at 2011-01-20 13:18:13 on Problem 1019
#include <iostream>
using namespace std;
int data[32005];
int main()
{
	int c=1,w=1;
	for(int i=1;i<32005;i++)
	{
		data[i]=c;
		if(i==9||i==99||i==999||i==9999)
			w++;
		c+=w;
	}
    int t;
	cin>>t;
	for(int i=0;i<t;i++)
	{
		int a,c=1;
		cin>>a;
		while(a-data[c]>0)
		{
			a-=data[c];
			c++;
		}
		//cout<<"第"<<c<<"区间"<<endl;
		w=1;
		int j;
        for(j=1;j<=c;j++)
		{
			if(a-w<=0)
				break;
			a-=w;
			if(j==9||j==99||j==999||j==9999)
				w++;
		}
		//cout<<"第"<<j<<"个数"<<endl;
		char t[256];
		string s;
		sprintf(t,"%d",j);
                 s = t;
		cout<<s[a-1]<<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