1. 程式人生 > >Newcoder 40 D.珂朵莉的假toptree(水~)

Newcoder 40 D.珂朵莉的假toptree(水~)

Description

珂朵莉想求 123456789101112131415... 123456789101112131415... 的第 n n

Input

第一行一個整數 n

n

( 1 n 1000 ) (1\le n\le 1000)

Output

第一行輸出一個整數,表示答案

Sample Input

3

Sample Output

3

Solution

簡單題,預處理出前 1000 1000 項即可

Code

#include<cstdio>
using namespace std;
const int maxn=1005;
int a[maxn];
int main()
{
	int res=1,p=1;
	while(res<=1000)
	{
		if(p>=1000)a[res++]=p/1000;
		if(p>=100)a[res++]=p/100%10;
		if(p>=10)a[res++]=p/10%10;
		a[res++]=p%10;
		p++;
	}
	int n;
	scanf("%d",&n);
	printf("%d\n",a[n]);
	return 0;
}