没有合适的资源?快使用搜索试试~ 我知道了~
众多名企(华为_阿卡_TCL_索尼_微软_百度_大唐)笔试面试题(C居多含C++及数据结构)改.doc
5星 · 超过95%的资源 需积分: 11 199 下载量 183 浏览量
2013-07-14
21:12:00
上传
评论 2
收藏 149KB DOC 举报
温馨提示
试读
33页
众多名企(华为_阿卡_TCL_索尼_微软_百度_大唐)笔试面试题(C居多含C++及数据结构)改.doc
资源推荐
资源详情
资源评论
上海华为的一道关于指针方面的编程题
int A[nSize],其中隐藏着若干 0,其余非
0 整数,写一个函数 int Func(int* A, int
nSize),使 A 把 0 移至后面,非 0 整数移
至数组前面并保持有序,返回值为原数据
中第一个元素为 0 的下标。(尽可能不使用
辅助空间且考虑效率及异常问题,注释规
范且给出设计思路)
c/c++笔试题(含参考答案 )
main()
{int count=0;
int m=9999;
while(m)
{
count++;
m=m&(m-1);
}
printf(count);
}
问 count 输出为多少?
答案:把 m 转换为二进制, 输出为这个二
进制中 1 的个数
最新 c/c++笔试题(含参考答案)
编写一个函数将 32 位整型参数分解为一个
4 字节数组,要求高位在前,低位在后,比如将
0XOOFEOOAC 分 解 为 数 组
OXOO,OXFE,OXOO,OXAC(注释:OX 不是
值,表示 16 进制数)
int i = 0X00FE00AC;
char c[20]={0};
char t[20]="0x00000000";
itoa(i,c,16);
strcpy(t+strlen(t)-strlen(c),c);
cout<<c<<endl;
cout<<t<<endl;
c/c++某大公司的两道笔试题(含参考答案 )
1.一群人围成一圈,123 的报数,报 3 者出
列,求最后一个人。
2.利用链表实现将两个有序队列 A 和 B 合
并到有序队列 H 中,不准增加其他空间。
请提供全一点的程序
第一题:
// kickout.cpp : Defines the entry point for the
console application.
//
#include "stdafx.h"
#include "malloc.h"
#include "stdio.h"
int main()
{
int m,n;
int kickouts = 0;
int *p = NULL;
int i ,j;
i=j=0;
printf("Please input m,n:");
scanf("%d,%d",&m,&n);
while(n<1)
{
printf("n doen't less 0 , retry n:");
scanf("%d",&n);
}
p=(int*)malloc(m*sizeof(int));
for(i=0;i<m;i++)
p[i]=1;
i = 0;
while(1)
{
i = i%m;
if(p[i++]) j++;
if(j == n)
{
p[i-1]=0;
j = 0;
1
kickouts++;
}
if(kickouts == m-1)
break;
}
for(i = 0;i<m;i++)
if(p[i]) printf("%d\n",i+1);
return 0;
}
2、升序还是降序?
以升序为例:
while(a != NULL && b!= NULL)
{
if (a->data < b->data)
{
h->data = a->data;
a = a->next;
}
else if (a->data == b->data)
{
h->data = a->data;
a = a->next;
b = b->next;
}
else
{
h->data = b->data;
b = b->next
}
h = h->next;
}
if (a == NULL)
{
while (b != NULL)
{
h->data = b->data;
h = h->next;
b = b->next;
}
}
else
{
while(a != NULL)
{
h->data = a->next;
h = h->next;
a = a->next;
}
}
几道 c 笔试题(含参考答案)
1. What is displayed when f() is called given
the code:
class Number {
public:
string type;
Number(): type(“void”) { }
explicit Number(short) : type(“short”) { }
Number(int) : type(“int”) { }
};
void Show(const Number& n) { cout <<
n.type; }
void f()
{
short s = 42;
Show(s);
}
a) void
b) short
c) int
d) None of the above
2. Which is the correct output for the
following code
double dArray[2] = {4, 8}, *p, *q;
p = &dArray[0];
q = p + 1;
cout << q – p << endl;
cout << (int)q - (int)p << endl;
a) 1 and 8
b) 8 and 4
c) 4 and 8
d) 8 and 1
第一个选 C;
虽然传入的是 short 类型,但是 short 类型
2
的构造函数被生命被 explicit,也就是只能
显示类型转换,不能使用隐式类型转换。
第二个选 A;
第一个是指针加减,按照的是指向地址类
型的加减,只跟类型位置有关,q 和 p 指向
的数据类型以实际数据类型来算差一个位
置,因此是 1。而第二个加减是实际指针值
得加减,在内存中一个 double 类型占据 8
个字节,因此是 8
一道 C++笔试题(含参考答案)
请用 C++写一个小程序,先请用户输入三
个字符串,然后把第一个字符串中出现的
所有的第二个字符串替换成第三个字符串
最后输出新的字符串。
呃,可以用 boost::regex 吗?几乎没代码
cin >> s1 >> s2 >> s3;
cout << regex_replace(s1, s2, s3);
公司的笔试题 [软件工程师]
设计线性方程求解程序,打印结果,输入
格式为:数字*变量 1+数字*变量 2.....=0,
变量为 a-z 的小写单个字母。
例如:输入 3*a+4*x+2=0, 5*a+3*x+4=0,求
a=?, x=?
完整的程序可能是这样
void RemoveHead(node **head)
{
if (head == 0 || *head == 0)
return
node * temp = *head;
(*head) = (*head)->next;
free (temp);
}
1.数据结构定义:通道和墙组成的迷宫。
用数组定义,1 代表墙 0 代表通道。
2.单链表结构定义:节点存储一个整型数,
给代码。合并二个已经按照该整型数从小
到大排好序的链表,合并后链表也是同样
排序好的。
简单,大概如下,伪算法
Node* uniteList(Node* first,Node*second)
{
Node*head=NULL;
Node*cur=NULL;
Node*temp=NULL;
while (first&&second)
{
if (first->key<second->key)
{
temp=first;
first=first->next;
}
else
{
temp=second;
second=second->next;
}
if (head==NULL)
{
cur=temp;
head=cur;
}
else
{
cur->next=temp;
cur=temp
}
}
if (first==NULL)
{
temp=second;
}
else
temp=first;
while (temp)
{
cur->next=temp;
temp=temp->next;
}
3
cur->next=NULL;
return head;
}
3.哪些操作会隐式调用 C++的拷贝构造函数?
按值返回,按值传递参数,用一个对象初始化
另一个对象
4.写出一个函数用来判断一个点到一个平面
的关系。用一个点和法向量来表示平面。
输入一个点和一个面,返回该点在面的前
面,后面,还是在这个面上。
对于第 4 题:
1)输入:
一个平面:由平面上的一个点 P0 和平面的
法向量 V0 表示.
一个点:PX
2)结果:判断 PX 和平面的几何关系
3)分析.可以使用向量的相关知识来解决这
个问题:
3.1 计算点 P0 到 PX 的向量 V = (PX-P0);
3.2 用点乘计算向量 V0 和 V 之间的夹角:
doProduct(V,V0) = A;
3.3 判断关系:
if (A == 0) ==> 夹角 90 度 ==> 点在面上
if (A > 0) ==> 夹角小于 90 度 ==> 和法向量
一致 ==> 在平面的正面
if (A < 0) ==> 夹角大于 90 度 ==> 和法向量
方向相反 ==> 在平面的反面
PS:在图形学中,平面分正反面,法向量所
指的面为正面,反之是反面。
1 、 write a program to implement float
operation using integer operation on a 32bits
processor. c or c++
2、write appropriate functions --void itoa(int
n,char *s),with pointer,not array indexing,it
would be appreciated very much if you could
optimize the code and draw a conclusion
regarding time complexity as well as space
complexity of both algorithms after comparing
between the optimized one and the other.
3 、 write a function --invert(x,p,n) --that
return x with the n bits that begin at position p
inverted(i.e 1 changed into 0 and 0 changed
into 1),leaving the others unchanged.
与 0001000 异或,
4、as far as Intel PXA27X and Linux Kernel
V2.4,describe briefly the general ways to
optimize the top-level application based on
MiniGUI or QT and give the examples to
explain it better.
1 What is the fastest way to count the number
of ones in a given number represented in a
binary form. You can assume that you have
infinte run time memory and the response time
should be O(1) always. Can you optimize the
memory used?
答案:
int bits_set( int word )
{
int tmp;
tmp = (word >> 1) & 033333333333;
tmp = word - tmp - ((tmp >> 1) &
033333333333);
return (((tmp + (tmp >> 3)) & 030707070707)
% 077);
}
2 What will be the complexity of finding the
duplicates in an array?
3 You are given a stack of punched cards, each
with m rows and n columns. Come up with a
algorithm to punch holes so that you can find
the missing cards (their sequences) in O(1)
time. You can assume that you are looking for
a missing card and only one is missing out of
all possibilities.
4 Write the binary search function in a C
language.
二分查找
4
5 In the given array, find the subsequence with
maximum sum and minimum length.
E.g. [10,25,-23,40,-12,39,7] The subsequence
[39,7] has sum of 46 with length 2.
最大子序列
6 Reverse a linked list
反转链表
7 Write an algorithm to compress a text file
压缩
8 How would you implement a BigInt class?
实现大数
9 If you are given x punched cards each with
m rows and n
columns, can u come up with a number
scheme to identify missing
patterns.
10 An absolute number is defined as one in
which each digit is
strictly smaller than the digit to its right (if
any). For e.g. 123,
478, 369 are all absolute numbers. 205, 485
are not. Write a program
to calculate these.
递增数
1.What is achieved by prefixing the 'static'
keyword to a file-level function or file-level
variable declaration?
字面理解:使用 static 修饰词使函数和变量
具有文件作用域的目的是什么?
减少名字污染,改变变量的存储区和生存期
2.Describe the difference between the “IS A”
and “HAS A” object relationships. Which is
the stronger relationship and why?
字面理解:stronger 应该是指功能更强大
HAS A;IS A 在编译期就决定了对象的行为,
但是 HAS A 可以在运行的时候改变"A"所
指向的对象 ,从而可以在运行时改变其行
为;HAS A 可以有 IS A 提供的所有特性(至
于访问权限,如果需要,可以赋予 friend 的关
系),范例如下
class B
{
public:
virtual int Foo();
};
继承:
class D:public B
{
......
};
组合:
class D
{
B*pB;//在这里 B 可以指向任何一个 D 的派
生类
};
面向对象的设计原则是优先使用组合.
3.Java & C# support interfaces directly with
the “interface” keyword.
C++ does not have an “interface” keyword.
How do you create an interface in C++?
Where/when is the use of interfaces especially
helpful?
这个是抽象类,应该没什么异议了
4.If a program requires a large number of
execution contexts what can be done to
minimise thread scheduling overhead?
队列,COM 里面就是对请求队列进行排队来
应对"客户端"的请求的
将这些上下文涉及的局部变量设计成数据
结构,然后在线程内部定义一个静态的数
据结构,在 while(1)循环内部使用数据结构
指针来访问上面的数据结构实体.
5. What does it mean to say that a function is
reentrant?
What are some of the ways of achieving
reentrancy?
1)什么是可重入性?
可重入(reentrant)函数可以由多于一个任
务并发使用,而不必担心数据错误。相反
不可重入(non-reentrant)函数不能由超过
一个任务所共享,除非能确保函数的互斥
5
剩余32页未读,继续阅读
fjp790308446
- 粉丝: 1
- 资源: 19
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页