编程高手请进

本帖于 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

请您先登陆,再发跟帖!