1 在 C 语言中下面那个语句的结果是 1 ?
main 函数正常结束的返回值
return 7&1;
char *p=”hello”; return p == “hello”;
上面都不对
2 F、G、X 都是32位有符号整数,F=X/2,G=X>>1,如果 F != G,那么:
编译错误
X 是奇数
X 是负数
F-G=1
G-F=1
3 3*4 的方格,有多少个长方形?
18
20
40
60
上面都不对
m*n表示高*宽。
思路一
穷举如下:
1*1=12,1*2=9,1*3=6,1*4=3,2*1=8,2*2=6,2*3=4,2*4=2,3*1=4,3*2=3,3*3=2,3*4=1. 总共60个。
思路二
从格子长边里面的5个点里选两个点,短边里面的4个点里选两个点,4个点分别以所在的边做垂直线,就会形成4条线,即一个长方形,一共有60种排列组合,即60个长方形。
4 一个直线将一个平面分成 2 部分,两条直线分成 4 部分,如果直线不平行,多条直线不共一点,问 100 条直线将平面分成几部分?
5051
5053
5510
5511
可以应用递推:f(n)=f(n-1)+n,其中f(1)=2,f(2)=2+2=4
求和为:2+2+3+4+5+…+100=1+5050=5051
5 n 个字符构成的字符串,假设每个字符都不一样,问有多少个子串?
n+1
n(n+1)/2
2^n-1
n!
对于一个字符串变量,例如”adereegfbw”,它的子串就是像”ader”这样可以从中找到的连续的字符串。字符串”adereegfbw”本身也属于它本身最长的子串。所以长度n的字符串的子串是B。
6 根据下面给的表和 SQL 语句,问执行 SQL 语句更新多少条数据?sql 语句:
update Books set NumberOfCopies = NumberOfCopies + 1 where AuthorID in select AuthorID from Books group by AuthorID having sum(NumberOfCopies)
表中数据:
BookID Tittle Category NumberOfCopies AuthorID
1 SQL Server 2008 MS 3 1
2 SharePoint 2007 MS 2 2
3 SharePoint 2010 MS 4 2
5 DB2 IBM 10 3
7 SQL Server 2012 MS 6 1
1
2
3
4
5
7 Suppose that a Selection Sort of 80 items has completed 32 iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved again)?
16
31
32
39
40
选择排序是每轮选一个最小值出来, 所以32轮就有32个排好了
8 What is the result of binary number 01011001 after multiplying by 0111001 and adding 1101110?
0001 0100 0011 1111
0101 0111 0111 0011
0011 0100 0011 0101
9 Which of following C++ code is correct?
int f() { int *a = new int(3); return *a; }
int *f() { int a[3] = {1, 2, 3}; return a; }
vector f() { vector v(3); return v; }
void f(int *ret) { int a[3] = {1, 2, 3}; ret = a; return; }
因为C不存在内存泄露的问题且可以得到想要结果,但所有选项都是可以编译通过的,无语法错误。A是内存泄露,没有delete,B数组是临时的,根本传不到主调函数里,D的问题同B一样。
10 Given that the 180-degree rotated image of a 5-digit number is another 5-digit number and the difference between the numbers is 78633, what is the original 5-digit number?
60918
91086
18609
10968
86901
如果作为选择题来做,每个选项花一点点时间验证一下就ok了。
如果作为填空题做:
首先,只有01689,5个数字反转扔有效。另外要注意,rotated image,数字所在位也变了。
考虑首位和末位,要求diff为7和3,只有1和8满足。1xxx8和8xxx1。
考虑倒数第二位3,由于末位退位,要diff4,只有0和6。所以是10×68和89×01。
最后看中间,不难了。
选D,10968。
11 Assume both x and y are integers, which one of the followings returns the minimum of the two integers?
y ^ ((x ^ y) & ~(x
y ^(x ^ y)
x ^ (x ^ y)
(x ^ y) ^ (y ^ x)
None of above.
选e,异或操作满足交换率和结合率,所以B的结果就是x,C的结果就是y,D的结果就是0,下面看A是否对,举个例子,x=0x0100,y=0x0011,A的结果是0x0100,得到的是两数中的大值,所以不对了。
12 What is the result of the following program?
char* f(char *str, char ch) {
char *it1 = str;
char *it2 = str;
while (*it2 != ‘′) {
while (*it2 == ch) { it2++; }
*it1++ = *it2++;
}
return str;
}
void main(int argc, char *argv[]) {
char *a = new char[10];
strcpy(a, “abcdcccd”);
cout
abdcccd
abdd
abcc
abddcccd
13 Consider the following definition of a recursive function, power, that will perform exponentiation.
int power(int b, int e) {
if (e == 0)
return 1;
if (e %2 == 0)
return power (b * b, e / 2);
return b * power(b * b, e / 2);
}
Asymptotically (渐进地) in terms of the exponent e, the number of calls to power that occur as a result of the call power(b, e) is
logarithmic
linear
quadratic
exponential
14 What is the output of the following piece of C++ code?
using namespace std;
struct Item {
char c;
Item *next;
};
Item *Routine1(Item *x) {
Item *prev = NULL, *curr = x;
while (curr) {
Item *next = curr->next;
curr->next = prev;
prev = curr;
curr = next;
}
return prev;
}
void Routine2(Item *x) {
Item *curr = x;
while (curr) {
cout c next;
}
}
void _tmain(void) {
Item *x, d = {‘d’, NULL}, c = {‘c’, &d}, b = {‘b’, &c}, a = {‘a’, &b};
x = Routine1(&a);
Routine2(x);
}
cbad
badc
dbca
abcd
dcba
15 Longest Increasing Subsequence (LIS) means a sequence containing some elements in another sequence by the same order, and the values of elements keeps increasing.For example, LIS of {2, 1, 4, 2, 3, 7, 4, 6} is {1, 2, 3, 4, 6}, and its LIS length is 5. Considering an array with N elements, what is the lowest time and space complexity to get the length of LIS?
Time: N^2, Space: N^2
Time: N^2, Space: N
Time: NlogN, Space: N
Time: N, Space: N
Time: N, Space: C
最长递增子序列,可以用动态规划(DP)算法来求解。
动态规划相当于递归的改进版,就是用辅助数组记录求解的中间过程来减少计算量。
需要一个长度为N的辅助数组记录当前子串的最长递增子序列的长度。
平均时间复杂度为NlogN,空间复杂度为N
16 Fill the blanks inside class definition
class Test {
public:
____ int a;
____ int b;
public:
Test::Test(int _a, int _b) : a(_a) {
b = _b;
}
};
int Test::b;
int _tmain(int argc, __TCHAR *argv[]) {
Test t1(0, 0), t2(1, 1);
t1.b = 10;
t2.b = 20;
printf(“%u %u %u %u”, t1.a, t1.b, t2.a, t2.b);
}
Running result: 0 20 1 20
static/const
const/static
–/static
const static/static
None of the above
17 In C++, which of the following keyword(s) can be used on both a variable and a function?
static
virtual
extern
inline
const
18 Which of the following statements are true?
Insertion sort and bubble sort are not effcient for large data sets.
Quick sort makes O(n^2) comparisons in the worst case.
There is an array: 7, 6, 5, 4, 3, 2, 1. If using selection sort (ascending), the number of swap operation is 6.
Heap sort uses two heap operations: insertion and root deletion.
None of above.
19 Which of the following statements are true?
We can create a binary tree from given inorder and preorder traversal sequences.
We can create a binary tree from given preorder and postorder traversal sequences.
For an almost sorted array, insertion sort can be more effective than Quicksort.
Suppose T(n) is the runtime of resolving a problem with n elements, T(n) = Θ(1) if n = 1; T(n) = 2T(n/2) + Θ(n) if > 1; so T(n) is Θ(n log n).
None of the above.
20 下面哪些是稳定排序
冒泡排序
快速排序
堆排序
归并排序
选择排序
21 Web 应用程序中常使用 MVC 模式,关于说法下面哪些是对的
型 ( Model )表示数据以及处理数据的业务逻辑
视图 ( View ) 是对模型的(可视化)展示,它渲染模型的结果,典型的是一个用户接口元素(user interface element)
控制器介于用户和系统之间,它接受用户的输入,指挥着模型和视图来完成输入对应的任务
MVC 的常用实践是,模型从用户接收 GET 和 POST 的请求,然后决定做神马,通过移交给控制器和视图
上面都不对
22 根据下面哪些可以确定一棵二叉树?
前序遍历和中序遍历
前序遍历和后序遍历
中序遍历和后序遍历
后序遍历
23 N个球中有一个假冒伪劣(重量不足),如果给你一个天平允许你测 3 次找出那个假冒伪劣,问 N 可能的值
12
16
20
24
28
24 Which Synchronization mechanism(s) is/are used to avoid race conditions among processes/threads in operating systems?
Mutex
Mailbox
Semaphore
Local procedure call
25 There is a sequence of n numbers 1, 2, 3,.., n and a stack which can keep m numbers at most. Push the n numbers into the stack following the sequence and pop out randomly. Suppose n is 2 and m is 3, the output sequence may be 1, 2 or 2, 1, so we get 2 different sequences. Suppose n is 7 and m is 5, please choose the output sequences of the stack:
1, 2, 3, 4, 5, 6, 7
7, 6, 5, 4, 3, 2, 1
5, 6, 4, 3, 7, 2, 1
5, 6, 4, 3, 7, 2, 1
1, 7, 6, 5, 4, 3, 2
3, 2, 1, 7, 6,5, 4
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.e1idc.net