Find the nth Digit Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others) Total submission (s): 8356 accepted submission (s): 2383
Problem description Hypothesis:
S1 = 1
S2 = 12
S3. = 123
S4 = 1234
.........
S9 = 123456789
S10 = 1234567891
S11= 12345678912
............
S18= 123456789123456789
..................
Now we connect all strings
S = 1121231234 ...... 123456789123456789112345678912 .........
Can you tell me the nth number in the S string?
Input The input is a number K, which indicates K queries.
Each row in the next K Rows has an integer N (1 <=n <2 ^ 31 ).
Output For each n, the nth number in S is output.
Sample Input
61234510
Sample output
112124
AC code:
# Include <stdio. h ># include <iostream> using namespace STD; int main () {int t, n; int I, j; for (I = 1; I <n; I ++) n-= I; If (N % 9) cout <n % 9 <Endl; elsecout <9 <Endl;} return 0 ;}
Code written by yourself can only process small data volumes
# Include <stdio. h ># include <iostream> using namespace STD; int main () {int t, n; int I, j, k ;__ int64 A [10000], sum [10000]; memset (sum, 0, sizeof (SUM); for (I = 1; I <= 10000; I ++) sum [I] = (1 + I) * I/2; scanf ("% d", & T); While (t --) {scanf ("% d", & N); for (I = 1; I <= 10000; I ++) {If (sum [I] <n & n <sum [I + 1]) {k = (n-sum [I]) % 9; break;} If (sum [I] = N) {k = I % 9; break;} If (k = 0) cout <9 <Endl; elsecout <k <Endl;} return 0 ;}