您的位置:首页 > 其它

[CodeForces]-672A-Summer Camp

2016-08-10 22:13 351 查看
[CodeForces]-672A-Summer Camp

原题:

A - Summer Camp

Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u

Description

Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.

This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is “123456789101112131415…”. Your task is to print the n-th digit of this string (digits are numbered starting with 1.

Input

The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.

Output

Print the n-th digit of the line.

Sample Input

Input

3

Output

3

Input

11

Output

0

Hint

In the first sample the digit at position 3 is ‘3’, as both integers 1 and 2 consist on one digit.

In the second sample, the digit at position 11 is ‘0’, it belongs to the integer 10.

题目大意:就是在123456789101112…这样一个按顺序的数列中,给出下标,然后得到对应的数。

题目分析:这种题一般就直接找规律就可以了。所以可以暴力一点,开个数组打表就可以了。我们可以发现我们要找的坐标的极限是1000这样,所以对应的数估计是400左右,我们把999跑出来就可以了

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std ;

const int max_n = 20000 + 10 ;
int a[max_n] ;

int main()
{
int count = 0 ;
for(int i = 1 ; i <= 999 ; i++)
{
if(i>=1&&i<=9){
a[++count] = i ;
}
else if(i>=10 &&i <= 99){
int shi = i/10 ;
int ge = i %10 ;
a[++count] = shi ;
a[++count] = ge ;
}
else if(i>=100 &&i <=999){
int bai = i/100;
int shi = (i%100)/10 ;
int ge = i %10 ;
a[++count] = bai ;
a[++count] = shi ;
a[++count] = ge ;
}

}
int n ;
cin>>n ;
cout<<a
;

return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  codeforces 水题