[关闭]
@BruceWang 2018-10-19T00:53:47.000000Z 字数 3158 阅读 1264

一家自动驾驶AI公司---纵目科技软件、算法笔试题

王抒伟


Settion 1: SW Program Questions

1. Implement the following macro to clear a 32 bit register's bit 4,5 and 6

  1. # define ClrRegBit456(x) ?
  2. Example:
  3. ClrRegBit456(REG_A) ;

Ans:

  1. #define ClrRegBit456(x) ((x)&0xFFFFFFC7‬)

2.What is problem of the following logic and how to modify it to make it work correctly?

  1. void allocate_mem(char *str)
  2. {
  3. Str = (char*) malloc(100);
  4. }
  5. void test()
  6. {
  7. char*str = NULL;
  8. allocate_mem(str);
  9. strcpy(str, "Hello World");
  10. printf(str);
  11. }

Ans:

  1. void allocate_mem(char **str)
  2. {
  3. *str = (char*) malloc(100);
  4. }
  5. void test()
  6. {
  7. char*str = NULL;
  8. allocate_mem(&str);
  9. strcpy(str, "Hello World");
  10. printf(str);
  11. free(str);
  12. }

3. Please list the system output

  1. unsigned char a;
  2. unsigned short b;
  3. unsigned int c;
  4. unsigned long d;
  5. unsigned long long e;
  6. unsigned int* p1, p2;
  7. std:: cout() << sizeof(a) << " " << sizeof(b) " " << sizeof(c) << " " << sizeof(d) << " " << sizeof(e) << " " << sizeof(p1) << " " << sizeof(p2) <<
  8. std::end1;

Complied and run by 32bit complier
Complied and run by 64bit complier

指针位数只和编译器的位数有关。
32位机器不能实现8位整数运算,longlong 其实是扩展。
64位机器可以实现8位整数运算,所以longlong 下放到long。

complier char short int long long long int* p1, p2
32 1 2 4 4 8 4, 4
64 1 2 4 8 8 8, 4

4. Please list the system output: TODO

  1. unsigned char a = 128;
  2. unsigned int b = ( a << 8 ) & ( a++ ) || (++a);

Ans:

c++ 中的优先级

  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. unsigned char a = 128;
  6. unsigned int b = ( a << 8 ) & ( a++ ) || (++a);
  7. printf("%d\n", a);
  8. printf("%d", b);
  9. return 0;
  10. }
  11. Output
  12. a = 130
  13. b = 1

  1. [推理题 1 ]猫鼠问题. TODO
    有一只猫在半径为r的圆周上以速度为v移动,猫只能在圆周上移动, 但可以自由改变方向。 圆心位置有一只老鼠。 老鼠可以在圆内自由移动, 但速度仅为 v/4。 老鼠按照什么样的策略/路线可以逃逸圆周而不被捕获。

Ans: 一家自动驾驶AI公司---纵目科技软件、算法笔试题


Settion 2: SW Program Questions

The following questions just need choose any two of them.

1. implement the following 2 functions.

  1. void * Alloc64Aligned (int nSize)
  2. void Free64Aligned ( void * p )

Ans:

  1. void * Alloc64Aligned (int nSize){
  2. char *ret;
  3. int block;
  4. int offset;
  5. int i;
  6. if (size<=0){
  7. return NULL;
  8. }
  9. block=1+size/8;
  10. ret=(char *)malloc(block*8);
  11. offset=((unsigned long)ret)%8;
  12. ret[0]=0;
  13. for (i=1;i<8-offset;++i){
  14. ret[i]=1;
  15. }
  16. return ret+8-offset;
  17. }
  18. void Free64Aligned ( void * p ){
  19. char *buf;
  20. int i;
  21. if (p==NULL){
  22. return ;
  23. }
  24. buf=(char *)p;
  25. for (i=1;i<8;++i){
  26. if (*(buf-i)==0){
  27. break;
  28. }
  29. }
  30. free(buf-i);
  31. }

2. 实现一个函数,计算兔子的数量

有一对兔子,从出生后第3个月起每生一对兔子,小兔子长到第三个月后又生一对兔子,假设兔子都不死,问第n个月兔子的总数为多少?

  1. Int CalculateRabbitCount(int monthNum)

Ans:

  1. int CalculateRabbitCount(int monthNum){
  2. int temp[32];
  3. int i;
  4. temp[0]=1;
  5. temp[1]=1;
  6. for (i=2;i<monthNum;++i){
  7. temp[i]=temp[i-1]+temp[i-2];
  8. }
  9. return temp[monthNum-1];
  10. }

3. 实现以下 random_sort 的函数, 对输入的数组做随机排序

rand函数是已知库函数, 可以返回0到1之间的一个浮点数
array 是输入的一个递增数组, size是数组的长度。 函数返回时的结果也存在array的数组中。

  1. float rand(); // return random value, 0 <= random value < 1
  2. void random_sort(int* array, int size)

Ans:

  1. //// T.3
  2. void random_sort(int* array, int size){
  3. int i;
  4. int p;
  5. int e;
  6. for (i=0;i<size-1;++i){
  7. p=(int)(rand()*(size-i));
  8. e=array[i];
  9. array[i]=array[i+p];
  10. array[i+p]=e;
  11. }
  12. }

4. 实现以下程序,对一帧8位灰度图实现双线性拉伸

  1. void bilinear_interpotation(unsigned char* src_buf,
  2. int src_width,
  3. int src_height,
  4. unsigned char* dst_buf,
  5. int dst_width,
  6. int dst_height)

Ans:

  1. 不会。。。
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注