anonymous No title
No License C
2022年01月13日
Copy Clone
#include <stdio.h>

int a[11] = {6, 7, 11, 12, 14, 18, 19, 21, 24, 28, 37};
int main(void){
    int key = 11;
    int l = -1;
    int r = sizeof(a)/sizeof(int);
    while (r-l > 1) {
        int m = l + (r - l)/2;
        if (a[m] > key) {
            r = m;
        }
        else {
            l = m;
        }
    }
    printf("%d", r);
    return 0;
}
#include <stdio.h>

int a[11] = {6, 7, 11, 12, 14, 18, 19, 21, 24, 28, 37};
int main(void){
    int key = 11;
    int l = -1;
    int r = sizeof(a)/sizeof(int);
    while (r-l > 1) {
        int m = l + (r - l)/2;
        if (a[m] > key) {
            r = m;
        }
        else {
            l = m;
        }
    }
    printf("%d", r);
    return 0;
}
No one still commented. Please first comment.