华声医疗笔试题
时间:2021-5-18-20:00
单选题1道
- 支持随机插入和删除的数据结构?
A.数组和链表
B.链表和哈希表
C.哈希表和队列
D.队列和堆栈
E.堆栈和双向队列
F.双向队列和数组
填空题2道
- 内存中构造了多少个类对象 (有引用,有指针,有new,有数组…)
- 求t
int m[3][3] = {0,1,2,0,1,2,0,1,2},i,j,t=1; for(int i=0; i<3; ++i) for(int j=i; j<=i; ++j) t += m[i][m[j][i]];
简答题4道
- 每个类的sizeof值(有空类A;有含有char,int变量的类B;含有virtal函数的类C,C的子类D,且含有char变量)
- 父函数和子函数,父函数中有虚函数,子函数中重写虚函数,都有构造函数和析构函数,求调用顺序。
- 求遍历次数
unsigned char t = 150; for(char i = 0; i<2*t; ++i) //todo
- 代码题:求两个二进制数相加的结果
string addBinary(string a, string b) { //二进制加法 int a_size = a.size(); int b_size = b.size(); int c = 0;//进位 int i = a_size-1; int j = b_size-1; string res;//保存结果 while(i>=0 && j>=0){ int d = a[i]-'0'+b[j]-'0'+c; c = d/2; res += d%2+'0'; --i; --j; } while(i>=0){ int d = a[i]-'0'+c; c = d/2; res += d%2+'0'; --i; } while(j>=0){ int d = b[j]-'0'+c; c = d/2; res += d%2+'0'; --j; } //返回 if(c!=0) res += c+'0'; for(int i=0; i<res.size()/2; ++i) swap(res[i],res[res.size()-i-1]); return res; }