由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - please help the following (in C or C+)
相关主题
这道G的题怎么做?url shorten有一点不明白
伪O(1) space的O(n)时间重新排列a1a2a3...b1b2b3...算法海归的行情
H1B 换公司的问题请教mySQL一条查询语句,有包子!
关于挂ITU 以后申请H1b会不会有问题Leetcode ==> Max Points on a Line, 我的程序到底哪出问题了
王垠被炒了? (转载) 纠结死了, 到底是用 GB2312 还是 UTF8 存中文文件名呢
给两个月notice被雷,求救贴请教一个问题
面试又挂了!难过死problem in R again ... sorry
OPT被拒,求助。
相关话题的讨论汇总
话题: following话题: data话题: int话题: value话题: count
进入JobHunting版参与讨论
1 (共1页)
n*c
发帖数: 22
1
I was asked the following?
Complete the body of the following function:
/** Return the index in array data of the element closest to or
equal to value. The array data has exactly data_count
elements. */
size_t find_nearest (int value, const int* data, size_t data_count);
Any quick code? thanks a lot
l*n
发帖数: 529
2
为什么这种code也来求啊?是作业么?
就是个简单循环一遍的事情,都不涉及到多指针,自己还搞不定的话,以后能干活儿么?

【在 n*c 的大作中提到】
: I was asked the following?
: Complete the body of the following function:
: /** Return the index in array data of the element closest to or
: equal to value. The array data has exactly data_count
: elements. */
: size_t find_nearest (int value, const int* data, size_t data_count);
: Any quick code? thanks a lot

n*c
发帖数: 22
3
I'm not computer guy, try to get similar C/C+ code, any suggestion is
appreciated. Thanks.
n*c
发帖数: 22
4
Can anyone show me a quick code?
many thanks.
n*c
发帖数: 22
5
do i need 指针? or just a array?
many thanks.
n*c
发帖数: 22
6
please help me with a quick code, i need online submit.
thanks.
A*****i
发帖数: 3587
7
size_t find_nearest(int value, const, int * data, size_t data_count) {
size_t res = 0;
int tmp1 = 0;
int tmp2 = value;

if (0 == data_count)
return data_count;

for (size_t i = 0; i < data_count; i++) {
tmp1 = value >= data[i]? (value - data[i]):(data[i] - value);
if (tmp1 < tmp2){
tmp2 = tmp1;
res = i;
}
}

return res;
}
老朽多年不写C和C++了,也不知道对不,nodejs害人不浅啊
f*****2
发帖数: 141
8
献丑了,不知道理解对不,请lz自己调试一下
int fabs(int var1, int var2);
size_t find_nearest(int value, const int* data, size_t data_count);
{
int index,indexValue, temp;
temp = fabs(value, data[0]);
indexValue = 0;
for(index=0; index < data_count; index++)
{
if(temp > fabs(value, data[index]))
indexValue = index;
}
return (size_t)indexValue;
}
int fabs(int var1, int var2)
{
retrun var1 >= var2? (var1-var2): -(var1-var2);
}
n*c
发帖数: 22
9
this is great, i'm trying understanding your code.
thanks for your kindness.
n*c
发帖数: 22
10
appreciated Avenssi (蛋疼帝) and fit2012 (fit2012).
Thanks so much.
1 (共1页)
进入JobHunting版参与讨论
相关主题
这道G的题怎么做?url shorten有一点不明白
伪O(1) space的O(n)时间重新排列a1a2a3...b1b2b3...算法海归的行情
H1B 换公司的问题请教mySQL一条查询语句,有包子!
关于挂ITU 以后申请H1b会不会有问题Leetcode ==> Max Points on a Line, 我的程序到底哪出问题了
王垠被炒了? (转载) 纠结死了, 到底是用 GB2312 还是 UTF8 存中文文件名呢
给两个月notice被雷,求救贴请教一个问题
面试又挂了!难过死problem in R again ... sorry
OPT被拒,求助。
相关话题的讨论汇总
话题: following话题: data话题: int话题: value话题: count