EMC 2009 笔试题目

下面是从EMC 2009招聘考题中选出的部分题目。
有些题目还未给出解答,希望大家能帮忙解决,现有的解答也可能错误,也希望大家指正。
1. Which RAID level has Striped array with independent disks and distributed parity?
A. RAID 1
B. RAID 2
C. RAID 3
D. RAID 5
E. RAID 10
Ans: RAID 5 参考http://hi.baidu.com/lolorosa/blog/item/44ca410b2808f6c53ac76352.html
2. How many subnets are possible with a class B address while the subnet mask is 255.255.255.128?
A. 255
B. 256
C. 254
D. 512
E. 510
Ans: D
A B C类的网络号长度分别为8,16,24
所以B类子网部分在后面两个字节中,而255.128中有9位的1和7位的0,所以子网个数应该是2^9=512
3. Which of the following problems can not be solved in O(N) time complexity and O(logN) space complexity?
A. Given an array of n numbers, find the kth smallest number in the array (1
B. Given an array of n numbers, find the largest or smallest number.
C. Given an array [a1,a2,...,ak,ak+1,...,an], change it to the array [ak+1,...,an,a1,a2,...,ak].
D. Given n closed intervals, find whether there is intersection.
E. Given a binary tree with n nodes,find out a given node and give the path from the root to the given node.
Ans: 暂无解答
分析:
A 这个是算法书上的问题,时间复杂度参考书本分析,考虑求中位数时用的是五个一组,则空间复杂度为S(n)=S(n/5)+n/5=O(n)
B这个不用讲了。
C这个编程之美和编程珠玑上都有,相当于循环移位,利用ba=(a'b')'来解决,也就是先对移位的两部分翻转,最后整个翻转,时间复杂度O(N),空间复杂度O(1)
E这个也不用讲了。
D我个人认为复杂度要O(nlogn)
4. What will be the output of the following C code?
#include
using namespace std;
int main()
{
char s1[] = "abcd";
char s2[10];
char s3[]="efgh";
int i;
i=strcmp(strcat(s3,strcpy(s2,s1)),strcat(s3,"abcd"));
printf("%d/n",i);
return 0;
}
A. efghabcd
B. 0
C. 1
D. Segment fault
E. None of the above
Ans:测试结果0
分析:参考自cppreference.com

Syntax:

#include 
char *strcpy( char *dest, const char *src );

The strcpy() function copies characters in the string src to the string dest, including the null termination. The return value is dest. Note that strcpy() does not perform bounds checking, and thus risks overrunning from or to. For a similar (and safer) function that includes bounds checking, see strncpy().

Syntax:

#include 
int strcmp( const char *str1, const char *str2 );

The function strcmp() compares str1 and str2, then returns:

Return value
Explanation

less than 0
str1 is less than str2

equal to 0
str1 is equal to str2

greater than 0
str1 is greater than str2

Syntax:

#include 
char *strcat( char *str1, const char *str2 );

The strcat function concatenates str2 onto the end of str1, and returns str1. For example:

printf( "Enter your name: " );
scanf( "%s", name );
title = strcat( name, " the Great" );
printf( "Hello, %s/n", title );

Note that strcat does not perform bounds checking, and thus risks overrunning str1 or str2. For a similar (and safer) function that includes bounds checking, see strncat.

5. Study the following C code
void show();
int main()
{
show();
}
void show()
{
printf("%d, %d, %d/n");
}
What will happen if it is compiled & run by an ANSI compiler?
A. It will compile and execute but nothing will be printed
B. It will compile but not link.
C. The compiler will generate an error.
D. The compiler will generate a warning.
E. It will compile, link and output with 3 integers.
Ans: E
我用GCC编译正常,运行输出三个整数。
g++编译出现Warning,说缺少参数。
g++ -O2 -g -Wall -fmessage-length=0   -c -o LinuxCPP.o LinuxCPP.cpp
LinuxCPP.cpp: In function `void show()':
LinuxCPP.cpp:31: 警告:格式字符串实参太少
LinuxCPP.cpp:31: 警告:格式字符串实参太少
g++ -o LinuxCPP.exe LinuxCPP.o
6. What's the output of the given program(compiled and run in IA-32)
int func(unsigned n)
{
int res = 0;
int h= n>>1;
while(n-->=0)
{
res += n>h?res+n:res-n;
}
return res;
}
int main()
{
printf("%d/n", func(100));
return 0;
}
A. -5050
B. 2401
C. 2500
D. 5050
E. None of the above
Ans:这个题目的变态充分反映了EMC的变态,注意此处的n是无符号数,也就是说n怎么整都>=0所以此程序是死循环。
7. What's the output of the given program(compiled and run in IA-32)
#include
using namespace std;
class Simple
{
public:
Simple(){}
~Simple(){}
static int i;
int func();
};
int Simple::i = 2;
int Simple::func()
{
static int i = 0;
return ++i;
}
int i=1;
int main()
{
Simple s;
for(int i=0; i<10; i++)s.func();
cout<< s.func() << s.i<< ::i <
return 0;
}
A. 1021
B. 1121
C. 1011
D. 1122
E. None of the above
Ans: 这个题目难度不是太大,主要考察作用域的问题,选择B
8. What's the output of the given program(compiled and run in IA-32)?
#include
#include
using namespace std;
struct Profile
{
char name[10];
char address[20];
int contentLen;
};
int main()
{
char buf[10*1024];
Profile *p = (Profile*)buf;
strncpy(p->name, "tom", strlen("tom"));
strncpy(p->address, "street", sizeof("street")*sizeof(char));
char c[] = "world";
p->contentLen = sizeof(c);
strncpy((char*)(p+1),c, sizeof("world")*sizeof(char));
cout<name<<", "<address<<", "<contentLen<<", "<<
return 0;
}
A. tom, street, 6, world
B. t, street, 1, w
C. tom, street, 5, world
D. t,s,1, world
E. Runtime error
Ans: A, 在gcc下测试。
9. Read the following code, the result of Func("tomorrow", "tomato") is:
#include
using namespace std;
int Func(char* strA, char* strB)
{
int lenA = strlen(strA);
int lenB = strlen(strB);
int **dist = new int*[lenA+1];
for(int i=0; i
dist[i]= new int[lenB+1];
for(int i=0; i
dist[i][0] = i;
for(int j=0;j
dist[0][j] = j;
for(int i=1;i
for(int j=1;j
{
int cost = strA[i]==strB[j]?0:2;
int del = dist[i-1][j]+1;
int ins = dist[i][j-1]+1;
int sub = dist[i-1][j-1]+cost;
dist[i][j] = del
}
int result = dist[lenA][lenB];
for(int i=0;i
delete []dist[i];
delete []dist;
return result;
}
A. 8
B. 5
C. 4
D. 6
E. None of the above
Ans:D 变态,不说了
10. What's the output of the given program?
#define f(a,b) a##b
#define g(a) #a
#define h(a) g(a)
int main()
{
printf("%s,", h(f(1,2)));
printf("%s/n",g(f(1,2)));
return 0;
}
A. f(1,2), 12
B. 12, f(1,2)
C. 12,12
D. f(1,2),f(1,2)
E. 1,2
Ans: B
11. One person plans to write one letter to each six different friends. She prepared six envelops with different names on it. How many different deliveries there could be, making the name of the person of the person who gets the letter is not the same as the name on the envelop?
A. 53
B. 127
C. 243
D. 265
E. 312
Ans: D 参考http://hi.baidu.com/lolorosa/blog/item/efcba1967e87dd14d31b7022.html
12. What is the last digit of the expression: 7^355?
A. 9
B. 7
C. 6
D. 3
E. 1
Ans: D
7^4的末尾是1,所以7^355此方的末尾等同于7^(355%4)的末尾,等于7^3此方的末尾,也就是3.
13. Assume you have two cups A and B. A's volume size is a and B's volume size is b. You are given a cup C whose volume size is c(c is unknown to you). There are no scale for these three cups. In which of the following scenarios, you can not fill the cup C with the cup A anc B.
A. a = 15, b=18, c=19
B. a=59, b=411, c=1347
C. a=28, b=126, c=13
D. a=15, b=6170,c=105
E. a=26,b=1005, c=17
Ans:C
原理分析(此题求解得到了唐斌同学的鼎力相助)
引自 http://www.hudong.com/wiki/%E8%A3%B4%E8%9C%80%E5%AE%9A%E7%90%86

在数论中,裴蜀定理是一个关于最大公约数(或最大公约式)的定理。裴蜀定理得名于法国数学家艾蒂安·裴蜀,说明了对任何整数a、b和它们的最大公约数d,关于未知数x和y的线性丢番图方程(称为裴蜀等式):

ax + by = m
有解当且仅当m是d的倍数。裴蜀等式有解时必然有无穷多个整数解,每组解x、y都称为裴蜀数,可用辗转相除法求得。

例如,12和42的最大公因子是6,则方程12x + 42y = 6有解。事实上有(-3)×12 + 1×42 = 6及4×12 + (-1)×42 = 6。

特别来说,方程 ax + by = 1 有解当且仅当整数a和b互素。

裴蜀等式也可以用来给最大公约数定义:d其实就是最小的可以写成ax + by形式的正整数。这个定义的本质是整环中“理想”的概念。因此对于多项式整环也有相应的裴蜀定理。
所以上述答案中
gcd(15,18)=3, 9 mod 3 =0
gcd(59,411)=gcd(59,411%59)=gcd(59,57)=1, 1347 mod 1 = 0
gcd(28,126)=gcd(28,126%28)=gcd(28,14)=14, 13 mod 14 !=0
gcd(15, 6170)=gcd(15,6170%15)=gcd(15,5)=5, 105 mod 5 = 0
gcd(26, 1005)=gcd(26, 17)=17 17 mod 17 =0
所以选择C

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值