Redian新闻
>
Does Apple Watch require a data plan?
avatar
Does Apple Watch require a data plan?# Apple - 家有苹果
c*2
1
Here's another old question:
avatar
s*x
3
快看,很快就会被删
avatar
S*E
4
Does it require a sim card, or just linked to a cell phone to get data?
avatar
c*2
5
Okay. Converted it from "exposed":
avatar
T*G
6
congrats, 包子
avatar
w*b
7
made in China
波和罩都是
avatar
m*s
8
not a cell phone.
iPhone only.

【在 S***E 的大作中提到】
: Does it require a sim card, or just linked to a cell phone to get data?
avatar
j*y
9
请问老兄这是哪个公司的面试题啊?
avatar
l*o
10
没看到啊
avatar
v3
11
not bad at all

【在 s*****x 的大作中提到】
: 快看,很快就会被删
avatar
j*y
12
老大,程序看不太懂,能否加点注释啊?
比如当i为0的时候,result[0]=0吧?因为digitsmaps[0]==""。这时候递归调用
doPrintTelephoneWords(phoneNum, 1, result)是要达成一个什么目的呢?
真是看不明白啊。
avatar
E8
13
avatar
r*k
14
看着像假的。
avatar
j*y
15
又看了一会儿,似乎有些明白,的确是巧妙的递推。但有些疑问:
1. char result[PHONE_NUMBER_LENGTH];应改为char result[PHONE_NUMBER_LENGTH+1]?
2. void printTelephoneWords( int phoneNum[] ){
char result[PHONE_NUMBER_LENGTH];
doPrintTelephoneWords( phoneNum, 0, result );
}似乎应该改为:
void printTelephoneWords( int phoneNum[] ){
char result[PHONE_NUMBER_LENGTH+1]; /* +1 for the string-ending 0x0
character */
for (int i = 0; i < 3; i++) {
doPrintTelephoneWords( phoneNum, 0, result );
}
}
否则出来的似乎只是da、db、dc而已。
我不太懂算法和数据结构,不对之处敬请指教。
avatar
f*0
16
这样也可以吃包子?
avatar
s*n
17
不错,硬了!
btw,罩是,波也是,不过波里面的filling估计是made in japan的硅胶

【在 w*b 的大作中提到】
: made in China
: 波和罩都是

avatar
c*2
18
1) from facebook
2) result[..+1] you can do that, but not necessary since C does index from 0
, the last idx is alwasy reseved for 0.
char try[2];
Either of these are fine:
try[0]='a';
try[1]='b';
try[2]='\0';
or strcpy(try,"ab");
3) curDigit is better named currentidx (from phoneNum[])
avatar
f*g
19
恭喜!恭喜!
avatar
p*n
20
是不是假牙掉下来了?
avatar
c*2
21
Ok. I play it further to get a utility program.
==================================================
/* telwords.c

Given a telephone number (or any number),
print all possible words based on
digits-letters mapping from telephone key pads.
*/

#include
#include
#include
static char *digitsmaps[]={
"0",
"1",
"ABC",
"DEF",
"GHI",
"JKL",
"MNO",
"PQRS",
"TUV",
"WXYZ",
"#",
NULL
};

void doPrintTelephoneWords( char *phoneNum, int len, int curIdx, char *
result)
{
int i;
int mapidx=phoneNum[curIdx]-'0';

if((mapidx>9)||(mapidx<0))
mapidx=10;

if( curIdx == len){
result[len]='\0';
printf("%s\n", result );
return;
}
for( i = 0; iresult[curIdx] = digitsmaps[mapidx][i];
doPrintTelephoneWords( phoneNum, len, curIdx + 1, result);
}
}
void printTelephoneWords( char *phoneNum )
{
char *result;
int len=strlen(phoneNum);

if(!phoneNum)
return;

result=(char*)malloc(len);
if(!result)
return;

doPrintTelephoneWords(phoneNum, len, 0, result);

free(result);
}
int main (int argc, char *argv[])
{
int i;

for(i=1;iprintf("Mappings of [%s]:\n",argv[i]);
printTelephoneWords(argv[i]);
printf("-------------\n");
}
return 0;
}
==================================================
A sample run:
telwords.exe 23 780
Mappings of [23]:
AD
AE
AF
BD
BE
BF
CD
CE
CF
avatar
u*7
22
pai baozi
avatar
c*o
23
不错,挺白的。

【在 s*****x 的大作中提到】
: 快看,很快就会被删
avatar
j*y
24
又琢磨了半天,你是对的。确实不需要再加一个循环,我搞错了。
就以你原来的程序为例:
doPr(p, 0, res) ->
currDigIdx=0, i=0, res[0]='d', doPr(p, 1, res) ->
currDigIdx=1, i=0, res[1]='a', doPr(p, 2, res) ->
print("da"), return ->
/* recursion-cycle finished for doPr(p, 2, res), but not finished yet for
doPr(p, 1, res) */
currDigIdx=1, i=1, res[1]='b', doPr(p, 2, res) ->
print("db"), return ->
currDigIdx=1, i=2, res[1]='c', doPr(p, 2, res) ->
print("dc"), return ->
/* now doPr(p, 1, res) is finished, return to the for-loop in doPr(p, 0,,
res) */
currDigIdx=0, i=1, res[0]='e', do(p, 1, res) ->
...
这个程序中,递归的流程保证了多重嵌套循环的依次展开,实在是很漂亮的设计。
不过,老大的程序似乎还是有些小问题的,还是拿原来的程序为例:
---
#define PHONE_NUMBER_LENGTH 2
...
if( curDigit == PHONE_NUMBER_LENGTH ){
result[2]='\0';
printf("%s\n", result );
return;
}
...
void printTelephoneWords( int phoneNum[] ){
char result[PHONE_NUMBER_LENGTH];
doPrintTelephoneWords( phoneNum, 0, result );
}
---
char result[2]定义了有效的内存访问空间是result[0]和result[1],result[2]='\0'
实质上已经是越界方位了,很危险,没有core dump只能说是幸运。
所以,我觉得应该改成char result[PHONE_NUMBER_LENGTH + 1];
avatar
u*h
25
baozi
avatar
o*1
26
why did the man rush to the water? it is shallow and dirty, and the girl
sure can swim though.

【在 s*****x 的大作中提到】
: 快看,很快就会被删
avatar
i*a
27
short legs
avatar
e*3
28
明显是假的,真的那可能这么浑圆挺拔?
avatar
c*o
29
不要嫉妒人家青春无敌。

【在 e********3 的大作中提到】
: 明显是假的,真的那可能这么浑圆挺拔?
avatar
e*3
30
青春无敌也要遵守万有引力呀。

【在 c*******o 的大作中提到】
: 不要嫉妒人家青春无敌。
avatar
w*d
31
ft,你怎么换个这么难看的头像?!

【在 c*******o 的大作中提到】
: 不要嫉妒人家青春无敌。
avatar
c*o
32
哦?没上web,我形象秀过期了?

【在 w********d 的大作中提到】
: ft,你怎么换个这么难看的头像?!
avatar
c*o
33
水里面。。。浮力抵消了。

【在 e********3 的大作中提到】
: 青春无敌也要遵守万有引力呀。
avatar
o*1
34
maybe there are no Higgs bosons around her breasts, therefore no mass and no
gravity on them

【在 e********3 的大作中提到】
: 青春无敌也要遵守万有引力呀。
avatar
e*3
35
扯,一堆波都在水面上,抵消个毛,这种的一看就是假的,估计是故意为了出名搞得一
个秀罢了。

【在 c*******o 的大作中提到】
: 水里面。。。浮力抵消了。
avatar
w*d
36
你上web看看,好难看耶

【在 c*******o 的大作中提到】
: 哦?没上web,我形象秀过期了?
avatar
c*o
37
靠,这么性感的锁骨你竟然不懂欣赏。

你上web看看,好难看耶

【在 w********d 的大作中提到】
: 你上web看看,好难看耶
avatar
w*d
38
性感个头,蓬头垢面,胸肌比女人还发达

【在 c*******o 的大作中提到】
: 靠,这么性感的锁骨你竟然不懂欣赏。
:
: 你上web看看,好难看耶

avatar
c*o
39
。。。

【在 w********d 的大作中提到】
: 性感个头,蓬头垢面,胸肌比女人还发达
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。