由买买提看人间百态

topics

全部话题 - 话题: const
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
b*****e
发帖数: 474
1
来自主题: Programming版 - in-class static member question
You are right & your example is great. Thanks.
But I was referring to the fact that, given:
class A {
public:
const static int a = 1;
const static char c = 'A';
};
You definitely need to define const char A::c; in your code,
but you don't need to write const int A::a; (there is danger
of not writing this, as you have pointed out).
In other words, it seems that const static int typically will be optimized
out, but const static char does not get this treatment.
ODR notwithstanding, I see the... 阅读全帖
O*******d
发帖数: 20343
2
来自主题: Programming版 - 我最近写的一个屏保程序
两幅图像在切换时,我用了颜色混合。 Windows的GDI没有比较好的混合颜色的方法。
我写这个屏保时不打算用OpenGL来做。于是自己写了一个混合颜色的class。 主要想法
是用空间换时间,。颜色混合用查表法。 两个颜色,不管红绿蓝,就是一个2维数组的
index,那个位置的颜色就是事先计算好的混合色。
#include
class ColorBlender
{
public:

ColorBlender(double alpha) { mAlpha = alpha;mLookupTable = NULL;
CreateTable(); }
~ColorBlender() {delete [] mLookupTable ;}
unsigned char Blend(unsigned char firstColor, unsigned char
secondColor);
void Blend(const unsigned char * pFirstColor, const unsi... 阅读全帖
g*********s
发帖数: 1782
3
how does the compiler know if the 1st get() or the 2nd get() should be
called?
#include
using namespace std;
class X {
public:
X(int x = 0): dat(x) {}
void print() const { cout << dat << endl; }
void inc() { dat ++; }
private:
int dat;
};
class Y {
public:
Y(const X& x): dat(x) {}
Y(const Y& y) { dat = y.get(); }
X& get() { cout << "ref" < const X& get() const { cout << "const ref" << endl; return dat;
}
private:
X dat;
};
int main()
{
X x(10);
Y y(x);
Y y2(y);
y.g... 阅读全帖
d****n
发帖数: 1637
4
来自主题: Programming版 - In C++, how to do matrix computation?
okay,没代码没真相。
here is my shabby codes and I want to share with you all.
output and analysis will be post soon
//file name matrix_op.c
#include
#include
#include
#include
#include
#include
#define _MX_INIT(type_t, row, col) ({ int i;\
type_t ** ret;\
ret=(type_t ** )malloc( row *sizeof(type_t*));\
for(i=0;i (ret);\
})
#defin... 阅读全帖
y**b
发帖数: 10166
5
来自主题: Programming版 - C++的"初始化"小结
以前读C++ Primer第四版中文版给自己写了个摘录,一搜索“初始化”,发现内容还很
庞杂,贴出来供参考,前面是页号。
042 两种初始化: 直接初始化(), 拷贝初始化=
044 变量初始化:类类型调用默认构造函数,局部内置类型不初始化,全局内置类型初
始化为零。
080 容器元素的值初始化(未指定元素的初始化式时):类类型调用默认构造函数,内置
类型置零。
097 数组元素的初始化(同变量初始化规则044):元素为类类型的数组调用默认构造函数
;局部内置数组不初始化,全局内置数组初始化为零。
117 new动态数组元素的初始化:类类型调用默认构造函数,内置类型不初始化,或指定
进行值初始化为零(且只能为零)。
151 new动态对象之初始化:类类型调用默认构造函数,内置类型不初始化,或指定进行
值初始化为任意值。
对提供了默认构造函数的类类型,没有必要进行值初始化, 会自动调用构造函数:
string *p=new string;和string *p=new string();无区别。
对内置类型或未定义默认构造函数的类类型,存在区别:int *p=new int... 阅读全帖
r**a
发帖数: 536
6
来自主题: Programming版 - 帮忙看一个code
我试了试下面两个code,第一个比我原来贴的那个速度明显快了但是还是比不上第二个。
Code1:
#include
#include
using namespace std;
class A
{
public:
A(const size_t N): _N(N) {}
vector > getXY()
{
//vector xytemp;
//for (size_t i = 0; i != 2; ++i)
// xytemp.push_back(i+3);
vector > xy(_N);
for (size_t i = 0; i != _N; ++i)
for (size_t j = 0; j != 2; ++j)
xy[i].push_back(j+3... 阅读全帖
k**********g
发帖数: 989
7
template
struct add_op {
T operator () (const T& src0, const T& src1) const
{ return src0 + src1; }
};
template
struct sub_op {
T operator () (const T& src0, const T& src1) const
{ return src0 - src1; }
};
template
class vec_apply {
void operator () (T* v_out, T* vec_in, long len, ...)
{
oper op; // creates a oper object (functor) on stack - does not take
space, because it will be optimized away when compiler find... 阅读全帖
h**********c
发帖数: 4120
8
来自主题: Programming版 - C++一问
应该可以
说不清,JAVA也可以这么干。
#include
#include
class A {
public:
A(const std::string& _name):Name(_name) {}
const std::string Name;
const std::string getName () {
return Name;
}
};
class B:public A {
public:
B():A("It is B") {}
const std::string getName () {
return Name;
}
};
class C:public B {
public:
const std::string Name;
C():Name("It is C") {}
const std::string getName () {
return Name;
}
};
int main () {
A a("It is A");
B b;
C c;
... 阅读全帖
d*******g
发帖数: 122
9
来自主题: Programming版 - 基本功不扎实,问个问题
这样展开是不对的。对于普通的类,一般比较函数这样写:
A::operator == ( const A& );
不能没有const。
但对于iterator,其概念是模仿指针的,对应const版本是 const_iterator,而不应是
const iterator&,所以应当是
iterator::operator == ( const_iterator );
当然也可以再重载一个
iterator::operator == ( const iterator& );
但是由于可以隐式转换,一般没必要。

const
d*******g
发帖数: 122
10
来自主题: Programming版 - 基本功不扎实,问个问题
前面的bool和后面的const我都省掉了,因为这些与他问的问题无关,这种刺儿就不用
挑了吧。否则你写的iterator和iterator又是什么意思?iterator是一个模板?
我刚看了一下gcc4.7.1的list类的iterator,与同类型比较的operator ==()为成员函
数,
iterator::operator==(const iterator&)
const_iterator::operator==(const const_iterator&)
但是iterator与const_iterator之间的比较为非成员函数
operator==(const iterator&, const const_iterator&)
这是因为定义iterator在先,所以无法在iterator的花括号内定义 iterator::
operator==(const const_iterator&)。那么与其先声明一个成员函数,然后在定义了
const_iterator之后再给出这个函数的定义,那不如直接定义非成员函数好了。
set和map的iterator情况与l... 阅读全帖
k***p
发帖数: 115
11
来自主题: Programming版 - 请教boost::any compile错误。
我的compiler是gcc 4.7。 多谢
$g++ testAny.cpp -o testAny
testAny.cpp: In function ‘void AnyTesting3()’:
testAny.cpp:66:54: error: no match for ‘operator=’ in ‘myPropertySet.std:
:map<_Key, _Tp, _Compare, _Alloc>::operator[], boost
::any, std::less >, std::allocator std::basic_string, boost::any> > >((* & std::basic_string(((
const char*)"BarrType"), (*(const std::allocator*)(& std::allocator<
char>()))))) = (BarrierType)... 阅读全帖
v******y
发帖数: 84
12
来自主题: Programming版 - c++ template specialization 参数
template int foo(const T &);
要specialization T 到const char *
咋是template <>int foo(const char *const &);
而不是template <>int foo(const const char * &);
b***i
发帖数: 3043
13
来自主题: Programming版 - 老年工程师转行做c++的新问题
今天,一个烙印审查我代码,愣说我有问题。我觉得是他有问题。
我的如下(大概这个意思,重要类用普通的替代说明问题)
有个类Point,有另一个类Store负责存储这些Point,使用了智能指针,然后定义了
event handler,可以把一个arg传给订阅的类。这个arg的两个成员是const T* Old,
const T* New.
还有一个NodeSet类存储了这个Point的指针在vector里面,不负责Point的生成和释放,
只存储哪些Point用了。如果负责存储的类替换了Point,那么这个NodeSet需要把原来
的那个旧的指针换成新的指针。注意这个指针是别的地方(Store)负责分配内存和释
放。
下面是我的代码,取得所有的指针,然后替换,然后放回去:
.....replacedHandler(const ... arg)
{
std::vector vP = ... GetAllPoints();
std::replace(vP.begin(), vP.end(),
const_cast(arg.Old),
... 阅读全帖
a**********s
发帖数: 588
14
来自主题: JobHunting版 - puzzle, 娱乐一下
void GuoHe(const vector& A)
{
sort(A.begin(), A.end());
const People& first = A[0];
const People& second = A[1];
Guohe(first, second);
Return(first);
int i = A.size()-1;
while (i > 2) {
const People& P0 = A[i];
const People& P1 = A[i];
GuoHe(P0, P1);
Return(second);
Guohe(first, second);
Return(first);
i -= 2;
}
if (i == 2)
Guohe(first, A[i]);
else
Guohe(first);
}
r****o
发帖数: 1950
15
来自主题: JobHunting版 - 问一个精华区里的题目
刚才试了一下,两个const按存在不存在取4种组合,函数都能正确工作,除了一些
warning以外。
const char *function1(void)
{
const char *s = "12345";
return s;
}
const char *function2(void)
{
char *s = "12345";
return s;
}
char *function1(void)
{
const char *s = "12345";
return s;
}
char *function1(void)
{
char *s = "12345";
return s;
}
是不是这4个函数等价?
h****b
发帖数: 157
16
来自主题: JobHunting版 - 请帮忙看道题 c++ operator overload
class xyz
{
public:
xyz &operator=(const xyz &rhs);
const xyz& operator+(const xyz &rhs) const;
const xyz& operator+(int m);
private:
int n;
};
main()
{
xyz a,b,c;
a=b+c+5; //为啥不对: binary '+' : no operator found which takes a right-
hand operand of type 'int' (or there is no acceptable conversion)
}
感谢
v******a
发帖数: 54
17
来自主题: JobHunting版 - 请问一道c++题目
class X {
public:

X & operator = (const X& r) ;
const X& operator+(const X&r) const;
const X& operator+(int m);
private:
int n;
};
Which statement is illegal, and why?
int main()
{
X a,b,c;
//A. a= a = b+c;
//B. a = a+5+c;
//C. (c=a+a) = b+c;
//D. a = b+5;
//E. a = b + c + 5;
return 0;
}
h****b
发帖数: 157
18
来自主题: JobHunting版 - 1道brianbench 的题 c++
以下选哪一个
class String {
char *s;
int length;
public:
String(const char *);
String();
/* add code here */
};
int main()
{
String s1 = "abc";
String s2 = "def";

strcmp(s1, s2);
getchar();
return(1);
}
Referring to the sample code above, which one of the following member
functions do you add at the comment in order to allow the strcmp(s1, s2)
statement to compile?
operator const char*() const { return s; }
char* const operator() const { return s; }
operator char*
x***y
发帖数: 633
19
来自主题: JobHunting版 - C++ Q48: illegal operation (C33)
Then, I think the answer is a.
The problem is this declaration:
const X& operator+(const X& rhs) const;
then in a)
a+a is a.operator+(a) and notice a reference is returned。
we know that we can not return a reference to a local stack, a local static,
or a heap-allocated object, so the only possibility is that a itself is
returned. But as the + operation, we return the sum, in which the a's value
must be changed, which voilate the signature of pass by reference to const
and const function...

it.
i**********e
发帖数: 1145
20
另外,这是我的重写的新代码,我觉得比我之前的版本要简洁些。
而且这版本也处理'.'为一个任意字母。
bool match(const char *str, const char *pattern) {
const char *p1 = pattern, *p2 = str;
// If the first character is a letter, need to match letter by letter.
while (*p1 != '*') {
if (!*p1 && !*p2) return true;
if (!*p1 || !*p2) return false;
if (*p1 == '.' || *p1 == *p2) {
p1++;
p2++;
} else {
return false;
}
}
while (true) {
// Now *p1 must be '*'
while (*p1 && *p1 == '*') {
p1++;
... 阅读全帖
g**u
发帖数: 583
21
来自主题: JobHunting版 - Google Onsite 面经
用stl的priority_queue写了下multi-way merge, 请大家拍砖。
其中: myPair的第一个就是要存储的值, 第二个表示ownership.
/*
*multiple way merge using the priority_heap
*/
#include "vector"
#include "queue"
class myPair{
friend std::ostream & operator<<(std::ostream & out, const myPair &p)
{
out<<" ( "< return out;
}
public:
myPair(int x, int y):_first(x),_second(y)
{
}
bool operator >(const myPair & p)const
{
return this->_fir... 阅读全帖
S**I
发帖数: 15689
22
来自主题: JobHunting版 - 请教c++的string vector问题,谢谢!
error message说的很清楚:string类的operator<没有定义,改成这样子就行了:
#include
#include
#include
#include
#include
using namespace std;
bool comp(const string& s1, const string& s2){
return strcmp(s1.c_str(), s2.c_str()) < 0;
}
int main () {
char *m1[] = {"a","e","c","m"};
vector v1(m1,m1+4);
char *m2[] ={"n"};
vector v2(m2,m2+1);
vector u;
/* int m1[] = {1,2,3,4};
vector v1(m1,m1+4);
int m2[] ={... 阅读全帖
j**w
发帖数: 382
23
来自主题: JobHunting版 - 一道c++ primer的问题

ic is a constant. that is, the value of ic can not be changed.
(d) int * const cpi. It means, cpi is a constant, and cpi points to an int.
Since cpi is a pointer. "cpi is a constant" just means the cpi points to a "
fixed" address. Say nothing about the content of that fixed address.
If (d) is valid, we can do (*cpi)++. In this case, the value of ic is
changed. It's wrong.
For (e)
const int *const cpic. cpic is a constant, and is pointed to a const int.
Since ic is also a const int. It's good.
... 阅读全帖
c*******7
发帖数: 465
24
来自主题: JobHunting版 - 问个简单的C++ 函数参数问题
From "int *" to "const int *", C++ need to create a temporary const
pointer for you. Unfortunately, C++ Standard forbids creating such pointer
for non-const reference. This also explains why "const int * const &"
actually works as someone suggested.
c********2
发帖数: 56
25
来自主题: JobHunting版 - 贴个FLEXTRADE的在线C++测试的题
面的是Associate C++ Developer,下面是面试题,光顾着记题了,最后只有56%的通过
率,要到
80%才能ONSITE,算是帮大家做点贡献吧,他家在招人,赶快去投简历
1) #include
using namespace std;
struct A{
A(int value) : m_value(value){}
int m_value;
};
struct B:A {
B(int value):A(value){}
};
int main(){
try {
try{
throw B(5);
}
catch(A a){
a.m_value *=2;
throw;
}
catch(B b){
b.m_value -=2;
throw b;
}
}
catch(A a){
... 阅读全帖
g*****1
发帖数: 998
26
来自主题: JobHunting版 - 请教2道c++的题 (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: guagua1 (), 信区: Programming
标 题: 请教2道c++的题
发信站: BBS 未名空间站 (Tue Jan 10 19:21:47 2012, 美东)
class base{};
class derived{};
class derived2: public base, derived {};
which is true?
1) This is illegal
2) derived2 is derived public from base and private from derived
3) derived2 is derived public from base and public from derived
4) derived2 is derived public from base and protected from derived
class X{
public:
X& operator=(const X& rhs);
const X& operator+(con... 阅读全帖
s*******f
发帖数: 1114
27
来自主题: JobHunting版 - facebook一题
//码遍本版
//inside for LOOP:
//1st round: check (ling)(mind)(rabo)(ofooowingdingbarrwingmonkeypoundcake
//2nd round: check l(ingm)(indr)(aboo)(fooowingdingbarrwingmonkeypoundcake
//...
//this can avoid double check, and, O(n) time, for slice window
string SubStrWordsGreat(const char *str, const vector &vs){
map ms;
int len = strlen(str);
const char *end = str + len;
int lensub = 0;
if (vs.size() == 0)
return "";
int sz = vs[0].size();
for (ve... 阅读全帖
S**I
发帖数: 15689
28
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
S**I
发帖数: 15689
29
☆─────────────────────────────────────☆
gzou (gzou) 于 (Thu May 12 02:26:35 2011, 美东) 提到:
马上就要G on site了,
求祝福。
下面是从本版收集到的Google的试题,便于大家查询。
申明:有的附带有解释说明的,也来自于本版或者网络,大家自己看, 不保证真确
http://www.mitbbs.com/article_t1/JobHunting/31847453_0_1.html
本人ECE fresh PhD,背景是电路/EDA,跟G业务基本没什么关系
同学内部推荐的,很简单的一次电面就给了onsite
题都不难,但是自己没把握好机会,出了一些小bug。
总的感觉,出错就是硬伤,宁可从最简单的算法写起,也不能出错。
电面:
1,Skip list, http://en.wikipedia.org/wiki/Skip_list
写code实现struct skip_list * find(struct skip_list *head, int value)
2,sorted array... 阅读全帖
w****x
发帖数: 2483
30
来自主题: JobHunting版 - 说好得FG面经,回馈板上GGJJ
//Print strings with certain prefix in a sorted string array
void GetIndex(const char* strs[], int nBeg, int nEnd, char chr, int nPos,
OUT int& index1, int& index2);
void PrintComPrefix(const char* strs[], int n, const char* szPre)
{
assert(strs && szPre && n > 0);
const char* p = szPre;
int nIndex1 = 0;
int nIndex2 = n-1;
while (*p != 0 && nIndex1 >= 0)
{
GetIndex(strs, nIndex1, nIndex2, *p, p-szPre, nIndex1, nIndex2);
p++;
}
if (nIndex1 >= 0 ... 阅读全帖
w****x
发帖数: 2483
31
//Print strings with certain prefix in a sorted string array
void GetIndex(const char* strs[], int nBeg, int nEnd, char chr, int nPos,
OUT int& index1, int& index2);
void PrintComPrefix(const char* strs[], int n, const char* szPre)
{
assert(strs && szPre && n > 0);
const char* p = szPre;
int nIndex1 = 0;
int nIndex2 = n-1;
while (*p != 0 && nIndex1 >= 0)
{
GetIndex(strs, nIndex1, nIndex2, *p, p-szPre, nIndex1, nIndex2);
p++;
}
if (nIndex1 >= 0 ... 阅读全帖
w****x
发帖数: 2483
32
template
class SmartPointer
{
public:
SmartPointer(const SmartPointer& p) { addRef(p); }
SmartPointer(T* p) { assign(p); }
~SmartPointer() { decRef(); }
public:
SmartPointer& operator = (const SmartPointer& p)
{
if (this != &p)
{
decRef();
addRef(p);
}
return *this;
}
T* operator ->() const { return m_pVal; }
T& operator *() const { return *m_pVal; }
private:
void decRef()
{
... 阅读全帖
s***0
发帖数: 117
33
来自主题: JobHunting版 - 谈谈刚面的一个design题
class VendingItem
{
public:
typedef boost::shared_ptr Ptr;
enum ItemName
{
CocaCola;
Chips;
Cookies;
Condoms;
//etc
};

const unsigned int mPriceInCents;
const unsigned int getPrice() const {return mPriceInCents;};
}
class Cookies : public VendingItem
{
public:
Cookie(ItemName itemname) :
mPriceInCents(priceInCents){} // get priceInCents from some other
rule.
};
// A Rule is a class that takes 2 inputs
//... 阅读全帖
s***0
发帖数: 117
34
来自主题: JobHunting版 - 谈谈刚面的一个design题
class VendingItem
{
public:
typedef boost::shared_ptr Ptr;
enum ItemName
{
CocaCola;
Chips;
Cookies;
Condoms;
//etc
};

const unsigned int mPriceInCents;
const unsigned int getPrice() const {return mPriceInCents;};
}
class Cookies : public VendingItem
{
public:
Cookie(ItemName itemname) :
mPriceInCents(priceInCents){} // get priceInCents from some other
rule.
};
// A Rule is a class that takes 2 inputs
//... 阅读全帖
r*c
发帖数: 167
35
来自主题: JobHunting版 - L家电面
二爷,坑爹算法来也。用状态机搞砸一切面面!哈哈
#include
#include
#include
using namespace std;
class Numericality;
void TestNumericality();
void TestNumericalityHelper(const string& str, const bool expected,
Numericality& nc);
class Numericality
{
public:
struct State
{
const string _str;
int _index;
State() {}
State(string s, int i) : _str(s), _index(i){}
virtual State* MoveNext(){
if(_str.empty() || _index < 0 || _index >= _str... 阅读全帖
w****x
发帖数: 2483
36
int mul(const char*& p);
int num(const char*& p);
int Add(const char*& p)
{
int res = mul(p);
while (*p == '+' || *p == '-')
{
if (*p == '+')
res += mul(++p);
else
res -= mul(++p);
}
return res;
}
int mul(const char*& p)
{
int res = num(p);
while (*p == '*' || *p == '/')
{
if (*p == '*')
res *= num(++p);
else
res /= num(++p);
}
return res;
}
int num(const char*& p)
{
bool b... 阅读全帖
w****x
发帖数: 2483
37
int mul(const char*& p);
int num(const char*& p);
int Add(const char*& p)
{
int res = mul(p);
while (*p == '+' || *p == '-')
{
if (*p == '+')
res += mul(++p);
else
res -= mul(++p);
}
return res;
}
int mul(const char*& p)
{
int res = num(p);
while (*p == '*' || *p == '/')
{
if (*p == '*')
res *= num(++p);
else
res /= num(++p);
}
return res;
}
int num(const char*& p)
{
bool b... 阅读全帖
r***e
发帖数: 29
38
来自主题: JobHunting版 - BBC 编程风格面试题,求指教
最后个人标准答案
#ifndef _ROMON_HEADER_
#define _ROMON_HEADER_
#define _DEBUG_
#include
#include
//ROMON digits
const std::string ROMON_DIGITS[] = {"I","IV","V","IX", "X","XL","L","XC","C"
,"CD","D","CM","M" };
//ROMON scale
const int ROMON_SCALE[] = {1, 4, 5, 9, 10, 40, 50, 90, 100, 400, 500, 900,
1000};
const int ROMON_MAX = 3999;
const int ROMON_MIN = 1;
class RomanNumeralGenerator
{
public:
virtual std::string generator(int num) = 0;
};
class CRoman : public RomanNumeralGene... 阅读全帖
J**9
发帖数: 835
39
1) For this signature
char* add(const char*a, const char *b)
It's definitely caller-free since you can't modify either one.
(allocation within the function)
(Or use a static buffer, but not recommended)
2) You can overwrite a with this, assuming a has enough spaces:
char* add(char*a, const char *b)
3) It's all caller's responsibility:
char* add(const char*a, const char *b, char *results)
Caller pre-allocates a buffer and passes in, of course, frees it later IF it
's from heap.
Choice 3) is the r... 阅读全帖
r*c
发帖数: 167
40
//矩阵求连接图
#include
#include
#include
#include
#include
using namespace std;
enum ColorEnum{White, Black};
struct Cell
{
int row;
int col;
Cell(int r, int c): row(r), col(c){}
};
struct Cluster{
bool visited;
vector vec;
Cluster(int i, int j) : visited(false) {
vec.push_back(Cell( i, j));
}
bool isWithinRange(const Cell& a, const Cell& b){
return abs(a.row - b.row) <= 1 ... 阅读全帖
r*c
发帖数: 167
41
//矩阵求连接图
#include
#include
#include
#include
#include
using namespace std;
enum ColorEnum{White, Black};
struct Cell
{
int row;
int col;
Cell(int r, int c): row(r), col(c){}
};
struct Cluster{
bool visited;
vector vec;
Cluster(int i, int j) : visited(false) {
vec.push_back(Cell( i, j));
}
bool isWithinRange(const Cell& a, const Cell& b){
return abs(a.row - b.row) <= 1 ... 阅读全帖
i******a
发帖数: 11
42
来自主题: JobHunting版 - Qualcomm面经
个人背景是fresh cs PhD。面试挺顺利,感觉都不错,主要围绕简历上的项目讨论。但
不幸被拒。Hiring manager说 definitely impressed with your interview,但只有
一个职位。说是把我推荐给其他组了。 这个是客气话不? 这种还有戏么?Recruiter
电话里也说过我被推荐给其他组了,但是都快一个月了,也没消息。Recruiter也从不
回email。是不是还没有其他组表示感兴趣? Anyway, move on了。
1. Read code to say which c routine function it is. Interviewer want to see
how you understand a program.
00009 void *
00010 f1(register const void *p1, register const void *p2,
00011 register size_t n1, register size_t n2,
00012 int (*f2)(cons... 阅读全帖
i******a
发帖数: 11
43
来自主题: JobHunting版 - Qualcomm面经
个人背景是fresh cs PhD。面试挺顺利,感觉都不错,主要围绕简历上的项目讨论。但
不幸被拒。Hiring manager说 definitely impressed with your interview,但只有
一个职位。说是把我推荐给其他组了。 这个是客气话不? 这种还有戏么?Recruiter
电话里也说过我被推荐给其他组了,但是都快一个月了,也没消息。Recruiter也从不
回email。是不是还没有其他组表示感兴趣? Anyway, move on了。
1. Read code to say which c routine function it is. Interviewer want to see
how you understand a program.
00009 void *
00010 f1(register const void *p1, register const void *p2,
00011 register size_t n1, register size_t n2,
00012 int (*f2)(cons... 阅读全帖
s********u
发帖数: 1109
44
来自主题: JobHunting版 - ebay二轮电面面经
感觉各种不顺,本来是约在了昨天,然后面试官忘了就约在今天,然后又迟到20分钟(
导致做题时间很紧张)。这次这个老印口音是真听不清楚,而且中间手机还莫名重启了
,真是无语。希望老印看
在他两次爽约的份上,放我一马。
0.先问了简历,还问我说项目都是用C++,会不会其他语言之类
1.Leetcode 3Sum原题。最大的失误是,我居然没有想到切换到旁边打开着的leetcode
窗口!!可能是有点紧张,又记得这题比较简单。然后我就先sort做,结果面试官不知
道这种方法,让我解释了大半天。然后写完了我才发现忘了处理重复的元素,而且有点
忘了怎么处理了。(其实最简单一个set记录tripple不就搞定了!!
阴差阳错,前天把所有做过的leetcode题做了一遍,居然漏了这道??
最后他问我重复的元素,我又解释说的确是没有处理,然后补充解释了下用hashtable
的方法,说这样就可以避免重复问题了。我估计面试官自己想的是这个方法。不过他好
像觉得我先sort的方法很“新颖”,所以还是说very good。
真是无奈,如果因为这种低级失误没过,真是怨不得别人了。
2.完全听不清楚他说什么,先问我... 阅读全帖
h**********y
发帖数: 1293
45
来自主题: JobHunting版 - c++疑难问题。。
下面这段code为什么是输出1413。。最后一个为什么是3
#include
#include
class A
{
public:
A(int n = 0) : m_n(n) { }
public:
virtual int f() const { return m_n; }
virtual ~A() { }
protected:
int m_n;
};
class B
: public A
{
public:
B(int n = 0) : A(n) { }
public:
virtual int f() const { return m_n + 1; }
};
int main()
{
const A a(1);
const B b(3);
const A *x[2] = { &a, &b };
typedef std::vector V;
V y({ a, b });
V::const_iterator i = y.begin();
...
阅读全帖
a***e
发帖数: 413
46
来自主题: JobHunting版 - Implement strStr() ?
http://en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt
不知道啊,但好像是可以得。我是觉得这种写法很简单, 比起同样的naive matching
char *strStr(const char *haystack, const char *needle) {
// if needle is empty return the full string
if (!*needle) return (char*) haystack;
const char *p1;
const char *p2;
const char *p1_advance = haystack;
for (p2 = &needle[1]; *p2; ++p2) {
p1_advance++; // advance p1_advance M-1 times
}
for (p1 = haystack; *p1_advance; p1_advance++) {
char *p1_old = (char*) p1;
p2 = needle;
while (*p1... 阅读全帖
x*******9
发帖数: 138
47
来自主题: JobHunting版 - 问一道G家热题
做了一下
>> 给定一个数字数组 ,其中每个元素是从末端数小于原数组中该元素的个数。求原数
组。
Time complexity: O(n * logn) // quick-sort + traverse
Memo complexity: O(n)
>> 令s[i]为a[i+1..n-1]中比a[i]大的数的数量。求最大的s[i]。要求O(nlogn)
Time complexity: O(n * logn) // Manipulate the Binary Indexed Tree
Memo compleixty: O(n)
#include
#include
#include
#include
#include
#include
using namespace std;
#define print(x) cout << x << endl
#define input(x) cin >> x
const int SIZE = 1024;
// @brief Bin... 阅读全帖
o********r
发帖数: 79
48
来自主题: JobHunting版 - google面经(挂了)
不要吵了。
我按beanbun的思路写了一遍,指教一下
typedef pair COORD;
void extend(COORD cur,
vector >& visited,
vector > matrix,
queue& current,
queue& next )
{
vector shift;
shift.push_back(make_pair(0,-1));
shift.push_back(make_pair(0,1));
shift.push_back(make_pair(1,0));
const int m = matrix.size();
const int n = matrix[0].size();
for(const auto s:shift)
... 阅读全帖
f*******r
发帖数: 976
49
来自主题: JobHunting版 - 问一道airbnb的面试题
题目就是external sort的思想。统计单词的次数,明显用map。注意文
件很大,要用long,以免溢出。
在你读文件并且增加这个map时,内存不够用,这是你要把临时结果写入临时文件。你
可以设计一个threshold,比如1 billion,当map的size达到这个值时,你就把map和临
时文件merge到另一个临时文件里。最后再把这个文件rename到原来的临时文件。再把
map清空,继续读原文件直到结束。 C++代码如下:
// Split the string into words that consists of a..z and A..Z.
void split(const string &s, vector &res) {
int beg = -1;
for (int i = 0, e = s.size(); i < e; ++i) {
if ((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) {
if (beg == ... 阅读全帖
s******g
发帖数: 755
50
【 以下文字转载自 Apple 讨论区 】
发信人: faucetQ (fq), 信区: Apple
标 题: [Mac Dev]整了个ObjectiveC的笔记,看看气氛对得上不
发信站: BBS 未名空间站 (Mon Feb 2 21:38:18 2009), 转信
整了个类似ObjectiveC学习笔记的东西,发上来大伙看看有兴趣不。
修改了一点,增加了NSAutoreleasePool的内容。
增加了NSString内容。
===========俺系分隔线==================
本文假设读者有基本的C编程能力,如果有C++或者Java的背景会更容易理解但是不是必须。
ObjectiveC基本语法
消息
在objectiveC中,向一个对象发送一个消息的语法为
[ obj method:parameter];
类似的功能在C++中写作
obj->method(parameter);
在java中写作
obj.method(parameter);
在smalltalk中写作
obj method:parameter
显而易见objectiveC和smalltalk... 阅读全帖
首页 上页 1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)