Problem H: 2023CSP演练-完善程序-3

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Special Judger Creator:
Submit:26 Solved:14

Description

2.

    本函数用二分法,在已按字母次序从小到大排序的字符数组list[len]中,查找字符c,若c在数组中,函数返回字符c在数组中的下标,否则返回-1

    [函数]

    int search(char list[]char cint len)

     { intlow=0high=len-1k;

       while(  (1)  )

       {   k=(low+high)/2;

           if(  (2)      return k;

           else

if(  (3)  )high=k-1;

                   else low=k+1;

        }

       return  -1;

    }

供选择的答案:

(1)

Alow=high    Bk==hight      C. low!=hight   D. low>hight

(2)

Alist[k]>low     Blist[k]c  C. list[k]>len  D.list[k]==c

(3)

Alist[k]c    Bk==hight      C. low!=hight   D. low>hight

Sample Input Copy


Sample Output Copy