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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/V5ZSQ/article/details/83301724

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;
}

猜你喜欢

转载自blog.csdn.net/V5ZSQ/article/details/83301724