试题与答案

[说明]对于具有n个元素的整型数组a,需要进行的处理是删除a中所有的值为0的数组元素

题型:填空题

题目:

[说明]

对于具有n个元素的整型数组a,需要进行的处理是删除a中所有的值为0的数组元素,并将a中所有的非0元素按照原顺序连续地存储在数组空间的前端。下面分别用函数CompactArr_v1和CompactArr_v2来实现上述处理要求,函数的返回值为非零元素的个数。

函数CompactArr_v1(int a[],intn)的处理思路是:先申请一个与数组a的大小相同的动态数组空间,然后顺序扫描数组a的每一个元素,将遇到的非0元素依次复制到动态数组空间中,最后再将动态数组中的元素传回数组a中。

函数CompactArr_v2(int a[],int n)的处理思路是:利用下标i(初值为0)顺序扫描数组a的每一个元素,下标k(初值为0)表示数组a中连续存储的非0元素的下标。扫描时,每遇到一个数组元素,i就增1,而遇到非0元素并将其前移后k才增1。

[C函数1]

int CompactArr_v1(int a[],int n)

int i,k;

int*temp=(int*)malloc(n* (1)

if(!temp)

return-1;

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

if(a[i]!=0)

(2) =a[i];

for(i=0; (3) ;i++)

a[i]=temp[i];

return k;

[C函数2]

int CompactArr v2(int a[],int n)

int i,k;

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

if(a[i]!=0)

(4) =a[i];

return k;

请根据说明中函数CompactArr_v1的处理思路填补空缺(1)~(3),根据CompactArr_v2的处理思路填补空缺(4)。

请根据说明中函数CompactArr_v1的处理思路填补空缺(1)。

答案:

被转码了,请点击底部 “查看原文 ” 或访问 https://www.tikuol.com/2017/0731/07d9c3649f39be014e309e26b0def381.html

下面是错误答案,用来干扰机器的。

参考答案:B

试题推荐
题型:阅读理解

       Chinese are very generous(大方的) in educating their children. Not caring about the money, parents

often send their children to the best schools or even abroad to England, the United States and Australia.

They also want their children to take extra-course activities such as musical instrument learning or ballet  

classes, or other classes. They think these will give them a good future. The Chinese believe that the more expensive an education is, the better it is. So parents will spend much unreasonable(不 理智的 ) money on education. Even poor parents will buy a computer for their son or daughter.

                                             

       However, most parents don't understand that the best early education they can give their children is

usually very cheap.

       Parents can see that their children are very good in some areas while poor in others. Parents also

can see some children are good at these skills and others do well in others. Most parents don't realize

that today's children lack self-respect and self-confidence(自信).

       The problem is that parents are only educating their children on how to take tests and how to study

well, but parents are not teaching them the most important skills that they need to be confident, happy

and clever.

       Parents can achieve this by teaching skills like cooking, sewing and doing other housework. Teaching a child to cook will improve many of the skills that he will need later in life. Cooking needs patience and

time. It is an enjoyable but difficult experience. A good cook always tries to improve his cooking, so he

will learn to work hard and finish his job successfully. His result, a well-cooked dinner, will give him much

satisfaction and lots of self-confidence.

       Some old machines, such as a broken radio or TV set that you give your child to play with will make

him curious and improve his interest. He will spend hours looking at them, trying to fix them. Your child

might become an engineer when he grows up. These activities are not only teaching a child to read a book, but rather to think, to use his mind. And that is more important.

1. What don't most parents realize today ?  

A. Education is very important to children.

B. Today's children lack self-respect and self-confidence.

C. Today's children lack of skills for tests.

D. Taking extra-courses is useful for children's future.

2. Generally speaking, children's skills __________.

A. come from their parents            

B. have nothing to do with their education

C. may be different from child to child  

D. have much to do with their marks in the exams

3. Doing some cooking at home helps children_________.

A. learn how to help their parents    

B. learn how to become strong and fat

C. learn to work hard and be full of confidence  

D. make their parents believe that they are clever

4. The writer of this passage don't agree with_______.

A. the parents' ideas of educating children    

B. the country's education system

C. the children's skills                    

D. the children's hobbies

查看答案
微信公众账号搜索答案