avatar
马思纯的脸没长开# TVChinese - 中文电视
J*8
1
The question is not hard. But I missed two key points.
The details below.
==========================================================
/*
example
char *words[] = {"foo", "bar", "baz", NULL};
setup(words);
1) First step:
isMember("foo") -> true
isMember("garply") -> false
2) Second step:
isMember("f.o") -> true
isMember("..") -> false
*/
#include
#include
#include
char *words[] = {"foo", "bar", "baz", "caz","cat",NULL};
int num=0;
void print_words(void)
{
int i=0;
while(words[i]){
printf("%s\n",words[i]);
i++;
}
}
/* arbitrary preprocessing. May be slow */
void setup(char *words[])
{
int i=0,j;
char temp[16];
while(words[i]){
i++;
}
num=i;

printf("num=%d\n",num);
//Brute force sorting
for(i=0;ifor(j=i+1;jif(strcmp(words[i],words[j])>0){
strcpy(temp,words[i]);
strcpy(words[i],words[j]);
strcpy(words[j],temp);
}
}
}
//Missed: Can't do qsort() lib call here. !!!!
printf("sorted.\n");
}
//Missed: in this case, it does NOT make sense to compare as strcmp
//only matched or not.
int matchdot(const char *s1, const char *s2)
{
if(!s1||!s2)
return 0;
while(*s1&&*s2&&((*s1==*s2)||(*s2=='.'))){
s1++;
s2++;
}

if(*s1||*s2)
return 0;

return 1;
}
/* returns whether word is a member of words given in setup() as fast as
possible */
int isMember(char *word) {
int low=0,high=num-1;
int mid;

while(high>=low){
mid=low+(high-low)/2;
if(!strcmp(words[mid],word))
return 1;
else if(strcmp(words[mid],word)>0)
high=mid-1;
else
low=mid+1;
}

return 0;
}
int isMemberdot(char *word) {
int i=0;
while(words[i]){
if(matchdot(words[i],word))
return 1;
i++;
}

return 0;
}
int main (int argc, char *argv[])
{
char buf[16];

print_words();
setup(words);
print_words();

//1) test cases
strcpy(buf,"cat");
if(isMember(buf))
printf("isMember(%s)=Yes\n",buf);
else
printf("isMember(%s)=No\n",buf);

strcpy(buf,"cot");
if(isMember(buf))
printf("isMember(%s)=Yes\n",buf);
else
printf("isMember(%s)=No\n",buf);


//2) test cases
strcpy(buf,"cat");
if(isMemberdot(buf))
printf("isMemberdot(%s)=Yes\n",buf);
else
printf("isMemberdot(%s)=No\n",buf);

strcpy(buf,"cot");
if(isMemberdot(buf))
printf("isMemberdot(%s)=Yes\n",buf);
else
printf("isMemberdot(%s)=No\n",buf);

strcpy(buf,"c.t");
if(isMemberdot(buf))
printf("isMemberdot(%s)=Yes\n",buf);
else
printf("isMemberdot(%s)=No\n",buf);

strcpy(buf,"..");
if(isMemberdot(buf))
printf("isMemberdot(%s)=Yes\n",buf);
else
printf("isMemberdot(%s)=No\n",buf);

return 0;
}
===================
running results
avatar
B*g
2
怎么木有呀
avatar
g*t
3
《芈月传》里,马思纯演的武王后魏颐,站在孙俪,刘涛,马苏旁边马上相形见绌。孙
刘马三人长得非常大气,特别是马苏,脸形轮廓分明,鼻子又高又挺,孙俪也很好,刘
涛稍逊。马思纯一脸刻薄小人样,更有鞋拔子之嫌。
avatar
l*v
4
what is the question?

【在 J******8 的大作中提到】
: The question is not hard. But I missed two key points.
: The details below.
: ==========================================================
: /*
: example
: char *words[] = {"foo", "bar", "baz", NULL};
: setup(words);
: 1) First step:
: isMember("foo") -> true
: isMember("garply") -> false

avatar
a*a
5
木吃到。

【在 B*****g 的大作中提到】
: 怎么木有呀
avatar
b*8
6
奶倒是被导演揉大了
avatar
l*r
7
我觉得是写程序实现开头那个example的功能把。

【在 l*****v 的大作中提到】
: what is the question?
avatar
l*o
8
墨有,要求补发
avatar
l*v
9
这就是带wildcard的string match。没有*应该不难吧。
avatar
f*u
10
等等,发出去50个,可能系统有限制,前50还没有出去。今天发布出去,明天一定会补
上。
avatar
l*v
11
面你的是不是个中国人

【在 J******8 的大作中提到】
: The question is not hard. But I missed two key points.
: The details below.
: ==========================================================
: /*
: example
: char *words[] = {"foo", "bar", "baz", NULL};
: setup(words);
: 1) First step:
: isMember("foo") -> true
: isMember("garply") -> false

avatar
a*a
12
信用卡额度不够?

【在 f*********u 的大作中提到】
: 等等,发出去50个,可能系统有限制,前50还没有出去。今天发布出去,明天一定会补
: 上。

avatar
n*n
13
问一下,他们用电话问问题阿?
那么多,难道用笔记下来吗?

【在 J******8 的大作中提到】
: The question is not hard. But I missed two key points.
: The details below.
: ==========================================================
: /*
: example
: char *words[] = {"foo", "bar", "baz", NULL};
: setup(words);
: 1) First step:
: isMember("foo") -> true
: isMember("garply") -> false

avatar
c*l
14
No.
avatar
L*h
15
同问

【在 n******n 的大作中提到】
: 问一下,他们用电话问问题阿?
: 那么多,难道用笔记下来吗?

avatar
o*s
16
必须的。而且要求双份。
avatar
J*8
17
No. A mostly white guy, fresh graduate.
Not friendly: *interrogated* me about
1) why want to leave current company
2) why choose facebook.
A bit bullshit. :-)
http://www.linkedin.com/pub/daniel-peek/7/571/b02

【在 l*****v 的大作中提到】
: 面你的是不是个中国人
avatar
J*8
18
http://collabedit.com/

【在 n******n 的大作中提到】
: 问一下,他们用电话问问题阿?
: 那么多,难道用笔记下来吗?

avatar
J*8
19
Not hard at all. But I focused on how to do wildcard matching, missed the
point to do linear lookup in dictionary in that case (binary search not
applicable any more).

【在 l*****v 的大作中提到】
: 这就是带wildcard的string match。没有*应该不难吧。
avatar
j*u
20
did he ask to use additional space to speed up lookup? ( is the source must
be an array)
otherwise the O(n) match is not interesting at all.
avatar
J*8
21
No, But I mentioned the best way is to build a trie, but that's too complex.
So let's do the binary search and/or linear search... He agrees. :-)
Do you have any better solution than trie?

must

【在 j*****u 的大作中提到】
: did he ask to use additional space to speed up lookup? ( is the source must
: be an array)
: otherwise the O(n) match is not interesting at all.

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