C/C++笔试题(4)

 1.    写出程序运行结果<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

int sum(int a)

{ auto int c=0;

  static int b=3;

c+=1;

b+=2;

return(a+b+C);

}

void main()

{ int I;

int a=2;

for(I=0;I<5;I++)

{ printf("%d,", sum(a))}

}

 

2.  int func(int a)

{int b;

 switch(a)

  { case 1: 30;

    case 2: 20;

    case 3: 16;

default: 0

}

return b;

}

func(1)=?

 

3:

int a[3];

a[0]=0; a[1]=1; a[2]=2;

int *p, *q;

p=a;

q=&a[2];

a[q-p]=?

 

4. 定义 int **a[3][4], 则变量占有的内存空间为:_____

 

5.编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入200412

31235959秒,则输出<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />200511000

 

6.写一个函数,判断一个int型的整数是否是2的幂,即是否可以表示成2^X的形式(不可

以用循环)   我只知道是用递推,大概写了一下,如下:

int IsTwoPow(int s)

{ if(s==1)return FALSE;

  s=s>>1;

  if(s>1)IsTwoPow(s);

  return (s==1)?TRUE:FALSE;//大概是这个意思,但是这一句似乎不该这么返回!

}

 

7、 AB从一堆玻璃球(共100个)里向外拿球,规则如下:

 (1)A先拿,然后一人一次交替着拿;

2)每次只能拿1个或2个或4个;

3)谁拿最后一个球,谁就是最后的失败者;

  AB谁将是失败者?写出你的判断步骤。

 

8.已知:无序数组,折半查找,各元素值唯一。函数原型是:Binary_Seach(int array[], int iValue, int iCount)array是数组,在里面用折半查找的方法找等于iValue的值,找到返回1否则0iCount是元素个数

 

9.统计一个字符串中字符出现的次数

 

10.100位以上的超大整数的加法(主要考虑数据结构和加法的实现)

 

11、.对如下电文:"CASTCASTSATATATASA"给出Huffman编码。

 

12、.int (* (*f)(int, int))(int)表示什么含义?

 

13、.x=x+1x+=1x++,为这三个语句的效率排序。并说明为什么。

 

14、中缀表达式 A-(B+C/D)*E的后缀形式是什么?

 

15、struct S1

{ char c;

int i;

};

sizeof(S1) = ?

class X{

public:

X();

virtual ~X();

void myMemberFunc();

static void myStaticFunc();

virtual void myVirtualFunc();

private:

int i;

char * pstr;

char a;

}

sizeof(X) = ?

 

16、找出两个字符串中最大子字符串,"abractyeyt","dgdsaeactyey"的最大子串为"acty

et"

 

17、有一百个整数,其中有负数,找出连续三个数之和最大的部分.

 

18、写一程序实现快速排序. 假设数据输入为一文件

快速算法描述如下

Algorithm Partition

Input: sequence a0, ..., an-1 with n elements

Output: permutation of the sequence such that all elements a0, ..., aj are les

s than or equal to all

elements ai, ..., an-1 (i > j)

Method:

 

choose the element in the middle of the sequence as comparison element x

let i = 0 and j = n-1

while ij

 

    search the first element ai which is greater than or equal to x

    search the last element aj which is less than or equal to x

    if ij

 

    exchange ai and aj

    let i = i+1 and j = j-1

After partitioning the sequence, Quicksort treats the two parts recursively by

 the same procedure.

The recursion ends whenever a part consists of one element only.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章