編程高手請進

來源: 布衣之才 2014-09-17 11:20:19 [] [博客] [舊帖] [給我悄悄話] 本文已被閱讀: 次 (2565 bytes)
本文內容已被 [ 布衣之才 ] 在 2014-09-17 12:39:23 編輯過。如有問題,請報告版主或論壇管理刪除.
Please implement the function
 
int isLetter(int n);
 
Allowed operators:  <, &.  
Parentheses are allowed without limit. 
No looping or if statements are allowed.
 
Please minimize the number of operations for efficiency. 最少可以幾次使用以上算符?
 
examples of output:
isLetter(10) = 0, isLetter('&') = 0,
isLetter('A') = 1, isLetter('m') = 1, isLetter(68) = 1 (68 is ascii code for 'D').
 

Hint: 
1. logical true = 1, logical false = 0.  for example (3 > 1) = 1, (3 < 1) = 0.
2. The binary and ascii values for letters are like:
a 097 01100001 A 065 01000001
b 098 01100010 B 066 01000010
c 099 01100011 C 067 01000011
d 100 01100100 D 068 01000100
e 101 01100101 E 069 01000101
 

所有跟帖: 

俺不是高手,但希望 implentation specifications 還要寫的簡潔清楚明白才行。 -拉兄弟一把- 給 拉兄弟一把 發送悄悄話 (60 bytes) () 09/17/2014 postreply 11:54:44

not even &&, ||, allowed? wait your solution only using <, & -爾思- 給 爾思 發送悄悄話 (0 bytes) () 09/17/2014 postreply 12:55:25

For this, & can be used in place of &&. no || allowed. -布衣之才- 給 布衣之才 發送悄悄話 布衣之才 的博客首頁 (0 bytes) () 09/17/2014 postreply 13:02:26

return (n < 123) & (64 < n) & ((n & 0x00DF) < 91); -爾思- 給 爾思 發送悄悄話 (50 bytes) () 09/17/2014 postreply 13:15:43

Great! -布衣之才- 給 布衣之才 發送悄悄話 布衣之才 的博客首頁 (53 bytes) () 09/17/2014 postreply 18:19:37

高! 實在是高... -iamagg- 給 iamagg 發送悄悄話 iamagg 的博客首頁 (0 bytes) () 09/18/2014 postreply 11:07:55

請您先登陸,再發跟帖!

發現Adblock插件

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

關閉Adblock後 請點擊

請參考如何關閉Adblock/Adblock plus

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

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