由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 又一道面试题,我是不是想多了?
相关主题
腆着脸在问一道Array in C
问个hash函数问题问个程序问题
一道Microsoft的面试题C++指针问题 int (*) [10]
a weak c question, how to pass an array into a function?用数组做参数,在函数内部如何知道数组的size?
请教大家一道C的面试题C++里get array size的问题 (转载)
一道c++ 题, 找出duplicate numbers这个怎么allocate memory?
An algorithm questionzero-sized array vs pointer
size不固定的struct怎么定义呀?问一个defining array 的问题
相关话题的讨论汇总
话题: array话题: int话题: function话题: size话题: hash
进入Programming版参与讨论
1 (共1页)
h**o
发帖数: 548
1
Question: Given the following prototype:
int compact(int * p, int size);
Write a function that will take a sorted array, possibly with duplicates,
and compact the array, returning the new length of the array. That is, if p
points to an array containing: 1, 3, 7, 7, 8, 9, 9, 9, 10, when the function
returns, the contents of p should be: 1, 3, 7, 8, 9, 10, with a length of 6
returned.
我觉得要分情况如果min(p)和max(p)差距小,就用设标注位的方法。
如果min(p)和max(p)差距大,size小,就用hash的方法。对吗?
用hash怎么做那?
t****t
发帖数: 6806
2
你说得很对,你想太多了。

p
function
6

【在 h**o 的大作中提到】
: Question: Given the following prototype:
: int compact(int * p, int size);
: Write a function that will take a sorted array, possibly with duplicates,
: and compact the array, returning the new length of the array. That is, if p
: points to an array containing: 1, 3, 7, 7, 8, 9, 9, 9, 10, when the function
: returns, the contents of p should be: 1, 3, 7, 8, 9, 10, with a length of 6
: returned.
: 我觉得要分情况如果min(p)和max(p)差距小,就用设标注位的方法。
: 如果min(p)和max(p)差距大,size小,就用hash的方法。对吗?
: 用hash怎么做那?

s****u
发帖数: 118
3
都排好序拉,一个个抽出来就好拉,为什么hash啊

p
function
6

【在 h**o 的大作中提到】
: Question: Given the following prototype:
: int compact(int * p, int size);
: Write a function that will take a sorted array, possibly with duplicates,
: and compact the array, returning the new length of the array. That is, if p
: points to an array containing: 1, 3, 7, 7, 8, 9, 9, 9, 10, when the function
: returns, the contents of p should be: 1, 3, 7, 8, 9, 10, with a length of 6
: returned.
: 我觉得要分情况如果min(p)和max(p)差距小,就用设标注位的方法。
: 如果min(p)和max(p)差距大,size小,就用hash的方法。对吗?
: 用hash怎么做那?

F*****n
发帖数: 1552
4
问一下,如果array size不知道该怎么做?
s****u
发帖数: 118
5
没法做

【在 F*****n 的大作中提到】
: 问一下,如果array size不知道该怎么做?
F*****n
发帖数: 1552
6
上次微软面试偶的时候问到这题了, 我问他size是否知道,他说no
结果我没做出来.
不过我觉得他也不是很懂
发信人: skatou (skatou), 信区: Programming
标 题: Re: 又一道面试题,我是不是想多了?
发信站: BBS 未名空间站 (Wed Sep 12 10:21:00 2007), 转信
没法做

【在 F*****n 的大作中提到】
: 问一下,如果array size不知道该怎么做?
a***f
发帖数: 45
7
估计面试官以为你在问resulting array的size,所以他说不知道。
h**o
发帖数: 548
8
那时不是还要把*p的最后几位没用的销掉,还是就让他去?

p
function
6

【在 h**o 的大作中提到】
: Question: Given the following prototype:
: int compact(int * p, int size);
: Write a function that will take a sorted array, possibly with duplicates,
: and compact the array, returning the new length of the array. That is, if p
: points to an array containing: 1, 3, 7, 7, 8, 9, 9, 9, 10, when the function
: returns, the contents of p should be: 1, 3, 7, 8, 9, 10, with a length of 6
: returned.
: 我觉得要分情况如果min(p)和max(p)差距小,就用设标注位的方法。
: 如果min(p)和max(p)差距大,size小,就用hash的方法。对吗?
: 用hash怎么做那?

b*********n
发帖数: 1258
9
sizeof(p)/sizeof(*p)不就是int array的size吗

【在 s****u 的大作中提到】
: 没法做
k****f
发帖数: 3794
10
@@@
看你的p是怎么定义了

【在 b*********n 的大作中提到】
: sizeof(p)/sizeof(*p)不就是int array的size吗
b*********n
发帖数: 1258
11
呵呵

【在 k****f 的大作中提到】
: @@@
: 看你的p是怎么定义了

s****u
发帖数: 118
12
作为参数传进去的sizeof(p)是指针size

【在 b*********n 的大作中提到】
: sizeof(p)/sizeof(*p)不就是int array的size吗
L*********r
发帖数: 92
13
msize
N********n
发帖数: 8363
14
俩指针,一个永远向前,另一个只有第一个指针遇到不同值时才向前并纪录。
一趟遍历不就完了。

【在 h**o 的大作中提到】
: Question: Given the following prototype:
: int compact(int * p, int size);
: Write a function that will take a sorted array, possibly with duplicates,
: and compact the array, returning the new length of the array. That is, if p
: points to an array containing: 1, 3, 7, 7, 8, 9, 9, 9, 10, when the function
: returns, the contents of p should be: 1, 3, 7, 8, 9, 10, with a length of 6
: returned.
: 我觉得要分情况如果min(p)和max(p)差距小,就用设标注位的方法。
: 如果min(p)和max(p)差距大,size小,就用hash的方法。对吗?
: 用hash怎么做那?

1 (共1页)
进入Programming版参与讨论
相关主题
问一个defining array 的问题请教大家一道C的面试题
c的问题(2)一道c++ 题, 找出duplicate numbers
一个C/C++面试题An algorithm question
电话面试题一问 (转载)size不固定的struct怎么定义呀?
腆着脸在问一道Array in C
问个hash函数问题问个程序问题
一道Microsoft的面试题C++指针问题 int (*) [10]
a weak c question, how to pass an array into a function?用数组做参数,在函数内部如何知道数组的size?
相关话题的讨论汇总
话题: array话题: int话题: function话题: size话题: hash