回複:有朋友的公司招程序員, 要特別強的。 附三道編程題目

來源: 東瓜太郎 2009-07-22 23:42:08 [] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (840 bytes)
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 < b) {
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);
}
}

所有跟帖: 

for 2, there's a much simpler way -Jamesxu- 給 Jamesxu 發送悄悄話 (14 bytes) () 08/14/2009 postreply 08:04:07

請您先登陸,再發跟帖!

發現Adblock插件

如要繼續瀏覽
請支持本站 請務必在本站關閉/移除任何Adblock

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

安裝Adblock plus用戶請點擊瀏覽器圖標
選擇“Disable on www.wenxuecity.com”

安裝Adblock用戶請點擊圖標
選擇“don't run on pages on this domain”