由买买提看人间百态

topics

全部话题 - 话题: sizeof
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)
f*********5
发帖数: 576
1
lo=0;hi=0; min=sizeof(str);
while(*str!='\0')
{
if (*str) not in target chars
{ str++;
if !(***)lo++;
hi++;
continue;
}
flag for *str ++;
if( all the flag for target chars >=1)
{ if (hi-lo set lo to next location that target chars happened in the
str;
flag for *str --;
}
hi++;
}
m*****s
发帖数: 19
2
来自主题: JobHunting版 - 问个ms的面试题
两个指针一头一尾pstart, pend.并且一直记录从pstart到pend的和sum
向后一位一位移动pend,更新sum
如果sum小于0了,向后移动pstart直到sum〉=0,(总可以〉=0的,因为重合时就〉=0)
如果大于等于0了就停止移动pstart,再移动pend。一直这样循环,直到pend-pstart =
sizeof(pointer) * (n-1)
这时候返回pstart

the
amount
you
between
I**********s
发帖数: 441
3
来自主题: JobHunting版 - Google点面
问了1) 研究, 2) 多线程程序设计, 3) 任意无穷字符串流, 内存有限, 找出唯一一对
重复字符串, 这个我说了哈希表和外部排序, 但是面试人说有更好的办法(后来想也许
是bloom filter), 然后追问外部排序的细节到结束. 估计要挂 :(
总结: 面试既是技术活, 又是运气活.
无论如何, 把我的准备工作放下面, 攒点rp, 希望对大家有所帮助.
Interview Qs
Data Structures
1. Integer
- find number of 1s
- next largest smaller
- smallest larger number
- determine if is palindrom
- itoa, atoi
- add 2 numbers w/o using + or arithmetic operators
- implement *, -, / using only +
- find max of two numbers w/o co... 阅读全帖
i***t
发帖数: 34
4
输入是一个字符串,然后判断这个字符串是不是26个字母都出现了,并打印出没有出现的
字母
万分感谢
char *getMissingLetters(const char *sentence){
int len;
char * ret;
int i, index = 0;
int marker[26]; //remember how many time char occurs in the string
if(sentence == NULL)
return "";
ret = (char*)malloc(sizeof(char)*26); //malloc buffer for return
string
if(ret == NULL) //malloc fail
return "";
len = strlen(sentence); //get string length
for(i = 0; i < 26
j**l
发帖数: 2911
5
来自主题: JobHunting版 - 离奇的Amzaon第一轮电面
int size = sizeof(int);
int bits = size * 8;
unsigned long num = 1;
num = num << (bits - 1);
long max_int = num - 1;
t****t
发帖数: 6806
6
来自主题: JobHunting版 - 离奇的Amzaon第一轮电面
actually this is more correct than using bit operations, although this is
the method for C. C++ uses numeric_limits::max() (which is uniform for
all numerical types). the problem of bit operations is, number of bits is
not necessary 8*sizeof(), although it is extremely unlikely.
BTW, if interviewer just want to check whether a (long) input is in the
range
of int, you can just check long(int(i))==i. This is much easier.
j**l
发帖数: 2911
7
来自主题: JobHunting版 - 离奇的Amzaon第一轮电面
这个对C不行吧,他说是C/C++,没说一定是C++
另外他提示说要用到sizeof
s*****g
发帖数: 5159
8
来自主题: JobHunting版 - 问一个bloomberg的面试题
sizeof(a) is usually 4 (pointer), you need to know the size of the array
regardless. your straight forward solution should be the answer.
b*********n
发帖数: 464
9
来自主题: JobHunting版 - bloomberg 面经
投了他家的senoir职位,超快,第二天就受到电话面试。电话面试两轮。记得的问题有
1. Strlen(“hello”)=?
sizeof(“hello”)=?
2. 实现int strcmp(char* s1, char* s2),念代码。
3. inline函数优点,放到什么位置(头文件还是cpp文件)?
4. 如果main函数只有如下结构
int main(…)
{
Try{…}
catch(){…}
}
并且这个catch语句catch了所有的exception,但是这个程序还是coredump了,问可能是什么问题引起的。
过几天受到onsite,安排好行程我竟然发现去的时候是头等舱,呵呵,人生第一次做头 等舱啊。当时特意去网上查了这趟班机,发现还有不少经济舱的座位,他家还挺大方的。Onsite总共5轮,前面两轮全是技术,每轮两人。问简历。现在记得的Technical
questions 有:
1. 写程序判断是little endian还是big endian
2. 写程序reverse一个c字符串
3. TCP serv
f*********5
发帖数: 576
10
来自主题: JobHunting版 - 请教一个常见的面试题的答案
why?
for example.sizeof(a)=8
lo=0,hi=8 //lo mean start index of binary search
// hi means end index of binary search
mid=(lo+hi)/2;
when u found that a[mid]=mid
u don't need to check a[0]..a[mid-1]...
then u can use binary search...
make sense?
a****n
发帖数: 1887
11
来自主题: JobHunting版 - One C++ question
你是想new obj数组吧?其他的应该都可以传入参数.
//create: using placement new
A* pa = static_cast (malloc(sizeof(A)*500));
A* pn = pa;
for (int i = 0; i < 500; ++i)
{
pn = new(pn) A(i);
++pn;
}
//destroy: explicit invoke destructor
pn =pa;
for (int i = 0; i < 500; ++i)pn++->~A();
free(pa);
a****n
发帖数: 1887
12
来自主题: JobHunting版 - another C++ question
//create: using placement new
A* pa = static_cast (malloc(sizeof(A)*500));
A* pn = pa;
for (int i = 0; i < 500; ++i)
{
pn = new(pn) A(i);
++pn;
}
//destroy: explicit invoke destructor
pn =pa;
for (int i = 0; i < 500; ++i)pn++->~A();
free(pa);
m****e
发帖数: 14
13
1. 以下程序少了关键一句吧?
code:bool has_num(int *integers, int target)
{
for (int i=0;i {
if(num_hashtable(target-*(integers+i))
{
return true;
}
}
return false;
}
少了 num_hashtable.add(*(integers+i)) 应该是个致命bug.
e******l
发帖数: 26
14
来自主题: JobHunting版 - 中国人面试果然很好人
刚刚被一位中国同胞面试,第3次phone,第一次被中国人面
果然不出所料被打击得很惨,
不过面试的同胞非常好人的给出了很中肯的意见,
指出俺太容易give up
俺确实是面试经验缺乏,准备也很不足,
谢谢这位同胞
面试的问题主要是一些基本的c/c++ java语法
主要涉及c/c++ java两种语言的一些区别与联系
问得比较细,
对了,还有padding,分配的内存不能为奇数,所以sizeof(something)的返回值
永远是偶数 (常识,俺居然忘了。。。)
几个算法问题
在100k个数中找top 100,
单向链表判断有无循环
还有0到n范围内找漏掉的数,n可以很大,但就算溢出仍然可以用一个整数就算出结果。
应该都是很常见的问题,俺大概是唯一一个答不出来的中国人吧。。。。
可惜一直没时间好好看版上的帖子
p******r
发帖数: 2999
15
来自主题: JobHunting版 - 中国人面试果然很好人
sizeof(char)是偶数么?
i****k
发帖数: 804
16
来自主题: JobHunting版 - 中国人面试果然很好人
跟编译器和编译器设置有关。
Microsoft C/C++ compiler: /Zp
/Zp1: sizeof = 1
s*********t
发帖数: 1663
17
来自主题: JobHunting版 - 看看这道题
跟reversestring的实现有关吧
但是编译错我觉得没道理。。
*input和input[]的区别是sizeof(后者)是8,(包含\0),前者是4,(指针大小)
但是函数调用传值的时候应该都是char*副本,不应该有区别。
但如果试图修改指针指的内容的话,第一个运行会出错,第一个指向的是个const
c**y
发帖数: 172
18
来自主题: JobHunting版 - 看看这道题
Sorry, I tested it by calling "sizeof(input)" for *input and input[]. 4 is
returned in both cases.
l*******o
发帖数: 791
19
来自主题: JobHunting版 - C++ Q21: size of virtual table
B, 因为每个含有若干virtual function的class只有一个vptr。这个“含有”包括即使
本类没有virtual function,但父类有,也就是继承下来的。所以A有一个VTABLE和一
个VPTR,B也有自己的一套。因为VPTR是在调用constructor时被insert进入的,所以
sizeof(B)就只是一个void * 的大小。在我的mac上是8
c**********e
发帖数: 2007
20
来自主题: JobHunting版 - C++ Q21: size of virtual table
b) sizeof(void*)
This is the correct answer. A virtual table is implemented as a plain
pointer to static table of jump addresses. There is no need to have more
than one per class, except in presence of multiple inheritance.
x***y
发帖数: 633
21
来自主题: JobHunting版 - C++ Q35: sizeof() (B20_20)
actually, enumerator can be cast to int; but inside a class, enumerator is
like static, no memory won't be allocated for a particular object...
c**********e
发帖数: 2007
22
来自主题: JobHunting版 - C++ Q35: sizeof() (B20_20)
So the answer is e)?
x***y
发帖数: 633
23
来自主题: JobHunting版 - C++ Q35: sizeof() (B20_20)
good to know....

and
on
to
P********l
发帖数: 452
24
来自主题: JobHunting版 - C++ Q35: sizeof() (B20_20)
Cool bean, dude.

and
may
on
rules to
e****9
发帖数: 316
25
来自主题: JobHunting版 - Amamon onsite 面经
KingMing code好快。
第二题如果只是链表到bst的话应该是不要其他的辅助数据的。
第二题就是那样的。我当时把那个递归和移动第一个点的位置的循环搞的不清楚。
第三题你可以看看Memory Alignment的东西。int的指针应该是能被4整除的,要不然可
能会有hardware exception.类似的问题还有对struct调用sizeof的问题。
第五题还有对角线上4个点,而且要先把能放的点push_back到vector里,然后再遍历
vector里面的点,对每个点递归调用。比如4,8初始已经填色,给你位置5,7不能填色
。如果不用vector的话,你会不知道4,8是初始填色的还是后面你递归的时候添上的。
五面第二题就是讨论,很多时候顾头顾不了脚,觉得应该是没有什么完美的方案。
P*******b
发帖数: 1001
26
来自主题: JobHunting版 - 问个题目
You are given have a datatype, say X in C.
The requirement is to get the size of the datatype, without declaring a vari
able or a pointer variable of that type,And, of course without using sizeof
operator !
t*q
发帖数: 104
27
来自主题: JobHunting版 - 问个题目
(int)((X*)0 + 1)

vari
sizeof
s*********t
发帖数: 1663
28
来自主题: JobHunting版 - 问个题目
why do you want to do this?

vari
sizeof
K******g
发帖数: 1870
29
来自主题: JobHunting版 - 请问以下程序运行结果
int main(void)
{
int i = 3;
int j;
j = sizeof((++i) + (++i));
int k = ++i + ++i;
printf("i=%d j=%d k=%d\n", i, j, k);
return 0;
}
h**e
发帖数: 13
30
来自主题: JobHunting版 - O(N) sort integer array
请详细说一下bitmap的解法。
我有个疑问,sizeof(bitmap)大约是4*128MB,把全部的数映射到这个bitmap,然后遍
历之,打印出所有的数(非0位),这个时间度是O(n)吗?
q**r
发帖数: 611
31
来自主题: JobHunting版 - C++ Q58: size of pointer (Bloomberg)
sizeof(char)不是1吗? 不懂
m*****n
发帖数: 2152
32
来自主题: JobHunting版 - C++ Q58: size of pointer (Bloomberg)
是啊,但sizeof(p)是4。
q**r
发帖数: 611
33
来自主题: JobHunting版 - C++ Q58: size of pointer (Bloomberg)
看成了十四。 为什么sizeof(p)是4呀?
h**k
发帖数: 3368
34
来自主题: JobHunting版 - 砸了面试,发面题
我用的机器也是32bit操作系统。你可以用sizeof(void *)看看,如果是4就是32位系统。
C++不允许这样给非const的静态成员初始化,我猜楼主是漏了const。
x****k
发帖数: 2932
35
来自主题: JobHunting版 - 砸了面试,发面题
第一题应该是 static const int SIZE = 100;(Effective C++, 3rd edition
, item 2)
具体结果depends compiler和编译选项。32 24是可能值之一。g++下是28 20,static
const int size不占sizeof的空间,按照4byte alignment。
可以用 -fdump-class-hierarchy dump出class的layout文件。
第二题在C++ compiler下应该是不确定。但我见过的编译器都是从右到左进行参数计算
,但g++会给warning “test.cpp:28: warning: operation on ‘i’ may be
undefined”,
test.cpp line 28 is like "fun(i++, i++)"
Effective C++, 3rd edition, item 17, P76
C++ compilers are granted considerable latitude in determining the ord
L*******e
发帖数: 114
36
来自主题: JobHunting版 - C++ Q: sizeof
What is the size of the following struct on 64-bit machines?
struct S1{
short a;
};
struct S2{
int a;
double b;
short c;
};
struct S3{
char a;
short b;
char c;
int d;
};
struct S4{
char a;
short s1;
char *pchar;
double d;
long l;
float f;
};
union U{
char *p;
short s;
long l;
};
c***2
发帖数: 838
37
来自主题: JobHunting版 - C++ Q: sizeof
padding
c******t
发帖数: 1500
38
来自主题: JobHunting版 - C++ Q: sizeof
2
24
12
24
4
m*****n
发帖数: 2152
39
来自主题: JobHunting版 - C++问题
如下的macro怎么用inline function改写?
#define PrintSize(type) \
cout << "size of " << #type << " is " << sizeof(type) << endl;
example:
PrintSize(char); will show "size of char is 1" .
M********5
发帖数: 715
40
来自主题: JobHunting版 - C++问题
#define PrintSize(type) \
do{ \
cout << "size of " #type << " is " << sizeof(type) << endl; \
} while(0)
l********n
发帖数: 54
41
来自主题: JobHunting版 - C++问题
great! Then, following code should work.
#include
#include
using namespace std;
template
inline void PrintSize()
{
cout<<"size of "<< typeid(T).name()<<" is " << sizeof(T)< }
struct A
{
int a;
double b;
};
int main(void)
{
PrintSize();
PrintSize();
PrintSize();
return 1;
}
p********7
发帖数: 549
42
来自主题: JobHunting版 - C++问题3
memset() 这理有问题吧
首先,如果sizeof是指包括了'\0'
其次,好像memset 用1去或者其他数是不能成功的,因为这样就实际是赋值为1,但是
是个
asic码,第三个memset超出char的范围了
x****k
发帖数: 2932
43
来自主题: JobHunting版 - C++一问
1, it really really depends on how complier is implemented.
2. usually size is sizeof(void *), not 4.
d**f
发帖数: 264
44
来自主题: JobHunting版 - 问个malloc问题
int *pInt = (int*)malloc(100*sizeof(int));
pInt++;
free(pInt);
Except mem leaking, is there any other problem ?
My suspicion is free() will mark the out of boundary mem location. So the
behavior will be undefined.
t******h
发帖数: 120
45

比如
int stack_push(STACK* stack, void* data, int size)
size是你要push的数据类型的大小,就是在内存里用多长的地址来表示。
再举个例子 你想要push一个int 就是
stack_push(stack, data, sizeof(int));
这样就知道这个void* 按一个int的长度来处理
建议你去看看youtube里面stanford大学的教程 Programming Paradigms
没记错里面的前10讲就是讲这方面 讲的很详细
y*********e
发帖数: 518
46
嗯,这个要看面试的时候沟通弄清楚要求了。
若是要存实实在在的data,那么大抵可以在stack_create的时候引入一个参数
,是为每一个元素的size。在push的时候,把数据拷贝到stack上。
typedef struct {
size_t count; /* no of elements in stack */
size_t capacity; /* max no of elements can be held */
size_t element_size; /* size of each element */
char* ptr;
} STACK;
/* Create a stack by specifying size of each element.
returns NULL if failure. */
STACK* stack_create(size_t element_size) {
STACK* s = malloc(sizeof(STACK));
if (!s) retur... 阅读全帖
f*******h
发帖数: 53
47
来自主题: JobHunting版 - 攒人品,twitter二面面经
LinkedList + Hashtable
Insert+Delete to Linkedlist. On insert, also insert the value and address
of the node to hashtable. On delete, also remove the value from hashtable.
On random, generate a random number with in the size 0..sizeof hashtable,
return the address of the node in that position.
All O(1)
i********s
发帖数: 133
48
来自主题: JobHunting版 - 攒人品,twitter二面面经
hashtable + array is the answer:
The array's element has link to the hash map entry and vice verses.
insert: insert an element to the hashtable, also append an element in the
array.
delete: remove the entry from the hashtable, using the link to find the
corresponding entry in the array. Remove the array element by moving the
last element to the current position.
random: generate a random number between 1 to sizeof array. pick an position
and corresponding entry in the hash table.
d*****t
发帖数: 41
49
来自主题: JobHunting版 - c++ question
这是假设输入的是32位的数,题目说don't make any assumption regarding the
size
of int.
(input>>(8*sizeof(a)-1))&1 == 1
K******g
发帖数: 1870
50
来自主题: JobHunting版 - c++ question
(a>>(sizeof(int)-1))&1 == 1

assumption
首页 上页 1 2 3 4 5 6 7 8 9 10 (共10页)