Codeforces Round #352 (Div. 2) A. Summer Camp 水题

A. Summer Camp

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.

Examples
input
3
output
3
input
11
output
0
Note

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.

 题意 : 题目意思很简单。

 思路 : 由于n才1000,其实可以不断取余放到字符数组里,比赛时太想睡觉了…… 结果用了数学方法,思路不清晰写了20+min结果 stdtest还WA了...鶸orz

 

 1 #include <stdio.h>
 2 #include <iostream>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll __int64
 6 using namespace std;
 7 
 8 const int INF = 0x3f3f3f3f;
 9 int main()
10 {
11     int n;
12     cin >> n;
13     if(n <= 9)
14         printf("%d\n", n);
15     else if(n - 9 <= 180)
16     {
17         if((n-9)%2 == 1)
18             printf("%d\n", 1 + (n-9)/20);
19         else
20             printf("%d\n",  (9+(n-9)/2)%10);
21     }
22     else
23     {
24         if((n-189)%3 == 1)
25             printf("%d\n", 1 + (n-189)/300);
26         else if((n-189)%3 == 2)
27             printf("%d\n", (n-189)/30%10);
28         else if((n-189)%3 == 0)
29             printf("%d\n", (99+(n-189)/3) %10);
30     }
31 
32 }

 

 

 

 

posted @ 2016-05-17 10:42  Lweleth  阅读(225)  评论(0编辑  收藏  举报