C++笔试题老题重发(5)

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 127 收藏 0 点赞 0 评论 0

31.找错
Void test1()
{   char string[10];
    char* str1=”0123456789″;
strcpy(string, str1);
}
Void test2()
{ char string[10], str1[10];
for(I=0; I<10;I++)
{str1[i] =’a’;}
strcpy(string, str1);
}
Void test3(char* str1)
{  char string[10];
   if(strlen(str1)<=10)
{ strcpy(string, str1);}
}

32.    找错
#define MAX_SRM 256
DSN get_SRM_no()
{  static int SRM_no;
   int I;
   for(I=0;I{
SRM_no %= MAX_SRM;
if(MY_SRM.state==IDLE)
{
    break;
}
}
if(I>=MAX_SRM)
return (NULL_SRM);
else
return SRM_no;
}
33.    写出程序运行结果
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));}
}

34.  int func(int a)
{int b;
 switch(a)
  { case 1: 30;
    case 2: 20;
    case 3: 16;
default: 0
}
return b;
}
则func(1)=?

35:
int a[3];
a[0]=0; a[1]=1; a[2]=2;
int *p, *q;
p=a;
q=&a[2];
则a[q-p]=?

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

37.
编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的下一秒。如输入2004年12
月31日23时59分59秒,则输出2005年1月1日0时0分0秒。

38.写一个函数,判断一个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;//大概是这个意思,但是这一句似乎不该这么返回!
}

39 A,B从一堆玻璃球(共100个)里向外拿球,规则如下:
 (1)A先拿,然后一人一次交替着拿;
(2)每次只能拿1个或2个或4个;
(3)谁拿最后一个球,谁就是最后的失败者;
  问A,B谁将是失败者?写出你的判断步骤。

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

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

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

43.对如下电文:”CASTCASTSATATATASA”给出Huffman编码。

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

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

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

47.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) = ?

48.找出两个字符串中最大子字符串,如”abractyeyt”,”dgdsaeactyey”的最大子串为”acty
et”

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

50.写一程序实现快速排序. 假设数据输入为一文件
快速算法描述如下
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.

评论列表
文章目录