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.
The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.
Print the n-th digit of the line.
3
3
11
0
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.
题意:"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15...". 连续的数 组成一个字符串(无空格 ,只是便于理解) 请输出n位置上的字符
题解: 可以直接暴力!!! 比赛的时候想多了 分析出 1~99 共189位 最多为一个三位数 分段分析 注意细节
1 #include<bits/stdc++.h> 2 #include<iostream> 3 #include<cstring> 4 #include<cstdio> 5 #include<map> 6 #include<queue> 7 #include<stack> 8 #define ll __int64 9 #define pi acos(-1.0) 10 using namespace std; 11 int n; 12 int main() 13 { 14 scanf("%d",&n); 15 if(n<=9) 16 { 17 cout<<n<<endl; 18 return 0; 19 } 20 if(n>9&&n<=189) 21 { 22 n=n-8; 23 int exm=n/2; 24 n--; 25 n=n%2; 26 if(n==0) 27 cout<<(exm+9)%10<<endl; 28 else 29 cout<<(exm+9)/10<<endl; 30 return 0; 31 } 32 if(n>189) 33 { 34 n=n-187; 35 int exm=n/3; 36 n=n-2; 37 n=n%3; 38 if(n==0) 39 cout<<(exm+99)%10<<endl; 40 if(n==1) 41 cout<<(exm+99)/100<<endl; 42 if(n==2) 43 cout<<(exm+99-(exm+99)/100*100)/10<<endl; 44 return 0; 45 } 46 return 0; 47 }