文学城论坛
+A-

回复:有朋友的公司招程序员, 要特别强的。 附三道编程题目

东瓜太郎 2009-07-22 23:42:08 ( reads)

1. don't get the question

2. easy way: print("a number in binary form")
normal way: assume 32bit integers as input, define an array of 32 integers (1, 2, 4, 8, ... 2^31). Run a loop using the 32 integers to bit and the input one by one and print the results.

3. easy way: cat input1 input2 | sort -n -m
c way:
/* END is a big big number that read() returns when it reaches the end of input file */
/* let's also assume that output() won't do anything when a/b are not assigned yet */
while (a != END || b != END) {
if (a ouput(a); a = read(input1);
} else if (a > b) {
output(b); b = read(input2);
} else {
output(a); output(b); a = read(input1); b = read(input2);
}
}

跟帖(1)

Jamesxu

2009-08-14 08:04:07

for 2, there's a much simpler way