This is the 24th day of my participation in the August More Text Challenge

Le Xin 01. Admission score

Thought analysis

I was a little lazy, but I knew I could have sorted it and returned it, but I thought I could have done it with two for loops

for(int j = 0; j < scores.size(a); j++){if(scores[i] <= scores[j]){ ret++; }}if(ret == k){
    return scores[i];
}
Copy the code

However, it was later found that it could not solve the problem of high ranking caused by repeated scores, but we can use it

for(int j = 0; j < scores.size(a); j++){if(scores[i] < scores[j]){ cot++; }}Copy the code

In this way, the score is returned if k is between cot and RET.

(It turns out that I’m running out of time, so I suggest doing it in the right order.)

03. Check-in sequence

Thought analysis

This looks like a regular problem, because there are nine digits from 1 to 9, each with one digit, there are 90 digits from 10 to 99, each with two digits, and there are 900 digits from 100 to 999, each with three digits.

Therefore, it can be determined in this way that there are 9 * I * 10i−110^{i-1} 10I −1 numbers for group I. For each digit I, there are 9 * I * 10I −110^{i-1} 10I −1 in this group

So for the former I group, there are 9 in the first layer, 99 in the second layer, 999 in the third layer, and 10I10 ^ I10i-1 in the I layer, so we can quickly determine in a loop what group this K is in.

After determining the group number, use k/ I to find the KTH/I digit in the group (if not divisible, discard the digits behind the decimal point) and use k% I to find the KTH/I digit in the group.

int getKthNum(long k) { 
    for (int i = 1;; i++) { 
        if (i * pow(10, i) > k) { 
            return to_string(k / i)[k % i] - '0'; 
        } 
        k += pow(10, i); }}Copy the code