1184: CSP完善程序-1

Memory Limit:128 MB Time Limit:1.000 S
Judge Style:Text Compare Creator:
Submit:77 Solved:8

Description

三、完善程序 (单选题 每小题3分,共计30)

1. 本程序输入一字符串,并将其中的大写字母变成小写字母。

    [程序]

   #include<cstdio>

    #include<iostream>

    #include<string>

    using namespace std;

   

    int main()

    {   int i=0;

       string str;

        printf("Enter a string.\n");   

        getline( cin, str);   

        for(i=0; (1) i<=str.size();i++)

       {  

           if(  (2) str[i]>='A'&&str[i]<='Z')

               str[i]+='a'-'A';

       }

       cout<<str; 

    return 0;

}

供选择的答案:

(1)

A.i<=strlen(str)   B.i<str.size()   C. strlen(str)<=i   D. str[i]=='\0'

(2)

A.str[i]>='A' && str[i]<='Z'      B.str[i]>='A' || str[i]<='Z'

C.str[i]<='A' && str[i]>='Z'      B.str[i]<='A' || str[i]>='Z'

 

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

    [函数]

    int search(char list[],char c,int len)

     { intlow=0,high=len-1,k;

        while(  (3)  )

        {   k=(low+high)/2;

            if(  (4)  )    return k;

            else

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

                   else low=k+1;

        }

       return  -1;

    }

供选择的答案:

(3)

A.low<=high      B.k==hight      C. low!=hight      D. low>hight

(4)

A.list[k]>low      B.list[k]>c      C. list[k]>len      D.list[k]==c

(5)

A.list[k]>c         B.k==hight      C. low!=hight     D. low>hight

 

3. 下面程序的功能是:在含有10个元素的 a数组中查找最大数,及最大数所在位置(即下标值),最大数可能不止一个。

    例如:若输入

    2  8    5    7    8    4    8    3    2    8

    则应输出

    The max:8

    Total:4    //最大数出现次数

    The positions:1  4  6  9

   【程序】

    #include <cstdio>

    #define M 10

    int fun(int *a,int  *n,int pos[ ])

    {

        int i, k, max = - 32767;

         k=0; 

        for(i=0; i<M; i++)

            if(  (6)  )  max=a[i];

        for(i=0; i<M; i++)

            if(  (7)  ) pos[k++]=i;

        *n=k;

        return max;

    }

  

    main()

    {

        int a[M],pos[M],i=0, j,n;

        printf("Enter 10umber:");

        for(i=0; i<M; i++)

           scanf("%d", (8) );      

        j=fun(   (9)    );

       printf("The max:%d\n",j);

       printf("Total: %d\n", n);

       printf("The position:");

       

       for (i=0; i<n;i++)

           printf ("%4d",  (10)  );

      printf("\n");

      return 0;

}  

供选择的答案:

(6)

A.a[i]>m     B. max>a[i]      C. a[i]>max        D. max>i

(7)

A.a[i]>max     B. a[i]==max      C. max>a[i]     D.a[i]>m 

(8)

A.&a[i]       B.a[i]         C. &a         D. i+y-x

(9)

A.a, n, pos      B. &a, n, pos       C. a, &n, pos       D. &a, &n, pos

(10)

A.a[i]       B. a[n]        C. pos[i]       D. pos



Input

n,m(n为据点数,聚点编号为1..n,m为边数,n,m<=500);

接下的一行为n个整数,为每个聚点的藏敌人数,用空格相隔,敌数<=1000 

Output