y*********e 发帖数: 518 | 1 Apache Common里面那个提供的是一系列的interface还有static的函数来做辅助。
真正的Closure还要提供语法上的支持。要提供一种简单的方法,能够把一个代码片段
当作参数带入函数。
比如,你给的链接里面的 Ruby 的示例代码:
def highPaid(emps)
threshold = 150
return emps.select { |e| e.salary > threshold }
end
这里的代码片段 |e| e.salary > threshold 其实会被编译成一个匿名函数。输入 e,返回
e.salary > threshold。所以输入类型是Employee,输出是Boolean。
但是Java 6在语法上就不支持,非要创建一个interface,然后new一个新的对象,把对
象当作参数带入select函数。麻烦之级。
除此之外,还要求编译器能自动鉴别数据类型 (Type Inference)。比如,我写一个匿
名函数,x => x + 1,这个 x 可以是 int,也可以是 long,还可以是 double。对于
支持ge... 阅读全帖 |
|
i**********e 发帖数: 1145 | 2 void foo(char** a){
*a = "hello world";
}
int main(){
char* c;
foo(&c);
printf("%s",c);
return 0;
}
这个程序有两个错误。
1) *a = "hello world";
This syntax is incorrect. The only exception is during intialization of a C-
style string constant like this: char *a = "hello world"; Note that this is a C-style string constant, if you try to modify the string, the result is undefined.
In this case, you should use strcpy(a, "hello world");
2) c is a pointer to a char. Since it is not initiali... 阅读全帖 |
|
g********d 发帖数: 203 | 3 Isn't string "Hello World" on foo's stack and it gets deallocated as soon as
foo is done? |
|
r*****n 发帖数: 20 | 4 恩 make sense
题意理解有误
这个题有比O(n^2)好的算法么?
写了一下O(n^2) 测了一下349901词的一个dichttp://www.math.sjsu.edu/~foster/dictionary.txt 要跑5-6分钟
return:
stekelenburg,hohohohohoho
代码如下
int myfunc(string a, string b){
return a.size()>b.size();
}
void foo(vector arr){
if(!arr.size())
return;
//step 1. sort w.r.t. lentgh of each word O(nlogn)
sort(arr.begin(), arr.end(), myfunc);
//step 2. compute signature for each word
vector sig;
for(long i=0; i阅读全帖 |
|
f*****e 发帖数: 57 | 5 Say you have a file containing name value pair, such as
foo: bar
a: b
foo: bar
a: c
The file may be huge, but the number of names are limited.
Given a name, find out how many times the name occurs in the file.
It looks to me there is a straight forward solution using hash table:
we preprocess the file, hash each name into the table, and keep the
count. We then use the same table to look up the name occurrence.
This should be programmed in C, so not stl. |
|
c*******t 发帖数: 1095 | 6 小公司不是亚马逊
第一题:
char* foo(char *s1){
char s2[32];
strcpy(s2,s1);
return s2;
}
int main()
{
char * t;
t=foo("hello");
printf("%s\n",t);
return 0;
}
问有啥问题,为什么?
没答出来,直接被拒鸟 |
|
D*********y 发帖数: 876 | 7 问了很多题
没怎么coding,基本上是讲一下思路
白板上画个图,就过了
这一天我就在不停的擦黑板
几乎没考算法题
求祝福!
谢谢大家
现在记得的面试题有:
简历的每句话都被问到了
一句一句的问,汗
就跟答辩似的,比答辩的时候讲的还细
解释一下research中用过的machine learning算法
有一个项目中做了一个数据库,把数据库结构画出来,解释各个entity之间的关系
join的种类,区别
sql用的是哪种(mysql之类)
difference between struct and class
features of object oriented design
give examples;how did you used OOD in your research
give the definition of the classes used in your research project
virtual function; pure virtual function; abstract class
for base/derived classes,
destruct... 阅读全帖 |
|
g**u 发帖数: 583 | 8
In fact, it is not exactely true.
In C++(Visual studio.net 2008), the first assignment, the compilation error
will complain for the first case, from b* --> a object. If you change it to
a *A=new b(), then the function called will be the one in the base because
the function in the base is non-virtual by default.
The second assignment, the compiler will error out again: can not convert
from b*-->a*.
BUT in Java, it is different, all these two will pass the compile time
test, and the output depe... 阅读全帖 |
|
y******5 发帖数: 43 | 9 Sorry for confusion. I know your code is for java, but I am not familiar
with it. So, I automatically using C++. Of course in C++ we need to change
the code from a to a*. Because size of b is no less than a, if we assign
address of an object of b to a-type pointer, b's own fields will be hidden.
That is why I said it is cut shorter.
If we assign address of an object of a to b-type pointer, there will always
be an error in C++.
In fact, it is not exactely true.
In C++(Visual studio.net 2008), th... 阅读全帖 |
|
s*****n 发帖数: 231 | 10 void foo (bool whatever) {
}
int main () {
char *str;
foo (str="hello");
printf ("%s\n", str);//line 1
return 0;
} |
|
f**********t 发帖数: 1001 | 11 对synchronization没啥基础。看了看career cup。
. Give a class foo, inside, it has a synchronized method. We have two
objects of foo, called, f1 and f2, if f1 and f2 are concurrently running,
can we guarantee the synchronized method being accessed by only one thread?
答案是不是yes?因为method已经是synchronized了,只能被一个thread所执行? |
|
s*******f 发帖数: 1114 | 12 u are goddamn right
template
void foo(int m[][width], int height){
for (int i = 0; i < height; ++i){
for (int j = 0; j < width; ++j)
printf("%d ", m[i][j]);
printf("\n");
}
return;
}
int main(){
int a[3][2] = {{1,2},{3,4},{5,6}};
foo<2>(a,3);
} |
|
g*********e 发帖数: 14401 | 13
I could think of an improvement to this. Label all the sub-strings when
doing a foo(). If foo(string) fails, all the intermediate strings are also
not de-composable. This would bring the total runtime to O(n).
Certainly we need to sort the dictionary by length before all these. |
|
g*********e 发帖数: 14401 | 14
I could think of an improvement to this. Label all the sub-strings when
doing a foo(). If foo(string) fails, all the intermediate strings are also
not de-composable. This would bring the total runtime to O(n).
Certainly we need to sort the dictionary by length before all these. |
|
q****x 发帖数: 7404 | 15 class X {
};
X foo() {
X x;
return x;
}
int main()
{
X x = foo();
}
其中ctor调用了多少次,3? |
|
l*****a 发帖数: 14598 | 16 按照理论如下
X foo() {
X x; ==〉constructor
return x; ==> return by value will call copy constructor 1)
}
int main()
{
X x = foo(); ==> this is also a way of using copy constructor 2)
}
return by value will generate a temp variable by copy constructor
是不是这个题de 1) 2)合二为一了? |
|
h*********y 发帖数: 24 | 17 都是很简单的题目,一些C++基础问题
写copy constructor, 为什么是reference,什么情况用shallow copy, 用什么机制共
享数据...两个C程序填空题。其中一个:
void foo(__)
{
__
...
__
}
const char* s;
foo(__)
printf("%s",s);
//结果要求是Hello world
Nth element in two sorted arrays. (注意array end情况); 加问如果反复调用这个
函数,怎么加速。
write sqrt function (注意分>1 和 <1两种情况)
题目都不难,但是要注意最好不要有bug
面试前别狂看题目,休息好最重要。
祝好运! |
|
A**u 发帖数: 2458 | 18 void foo(__)
{
__
...
__
}
const char* s;
foo(__)
printf("%s",s);
//结果要求是Hello world
这题咋做.... |
|
A**u 发帖数: 2458 | 19 void foo(__)
{
__
...
__
}
const char* s;
foo(__)
printf("%s",s);
//结果要求是Hello world
这题咋做.... |
|
S**I 发帖数: 15689 | 20 void foo (const char ** s){
*s = "Hello, World!";
}
foo(&s);
you need to read some elementary C books. |
|
h*****f 发帖数: 248 | 21 You will get a warning for the "incorrect" order of initialization for line
#14 as well.
Running 1, 2, 3 will have no warning or error.
#4 and 5 will have a runtime error (not compilation error as cplusplus.com
mentions).
#2 will have a compilation error (for all compilers?) if virtual D::foo()
isn't defined since the compiler doesn't know whether D::foo() should be
inherited from B or C.
#6 will have a runtime error because p3's vtable pointer is pointing to B's
vtable, and B has no virtual fun... 阅读全帖 |
|
i**********e 发帖数: 1145 | 22 Try this and figure out why:
void foo(int str[])
{
int len = sizeof(str)/sizeof(str[0]);
cout << "len = " << len << endl;
}
int main()
{
int a[] = {1,2,3,4};
int len = sizeof(a)/sizeof(a[0]);
cout << "len = " << len << endl;
foo(a);
return 0;
} |
|
s********k 发帖数: 6180 | 23 Unix Questions (shell questions apply to sh/ksh/bash)
• How many ways can you think of to remove a file called '-r'?
• How might one trap a SIGKILL from within shell, or C, Perl or
Python?
• Can a Unix process become unkillable? If so, how?
• How would you find the disk space consumed by a directory without
using du?
• What happens if /dev/zero is deleted from a running system? If
you want it back, how do you recover it?
• When using a termin... 阅读全帖 |
|
c*********n 发帖数: 182 | 24 • How many ways can you think of to remove a file called '-r'?
unlink/rm/...?
• How might one trap a SIGKILL from within shell, or C, Perl or
Python?
Perhaps there are nothing you can do with SIGKILL without patching the init.
..
• Can a Unix process become unkillable? If so, how?
Yes. uninterruptible sleep
• How would you find the disk space consumed by a directory without
using du?
don't know. find . | ls | awk | sort | awk | ... ?! &*^(&@#(*^@#
• W... 阅读全帖 |
|
c**********e 发帖数: 2007 | 25 class A {
public:
virtual int foo()=0;
};
A::foo() { return 0; }
That is can we have a function as pure virtual function
and also have defination like above?
Justify your answer. If yes, then tell me one situation
where we use that. If not tell me why not. |
|
b***i 发帖数: 3043 | 26 改成
class A{
public:
int a;
A():a(0){};
};
class B: public A{
};
void foo( A*& a ){
a->a=1;
}
void bar( B*& b ){
foo((A*&)b);
}
int main(){
B* b = new B();
bar( b);
cout<<(b->a);
return 0;
} |
|
h*****f 发帖数: 248 | 27 Hmm...a char can hold 0x0-0xFF. 128=0x80...so no overflow..
I guess the question is to detect whether the input occupies more than 1
byte?
You probably could *if* it were foo(char*) or foo(char&). |
|
b***d 发帖数: 87 | 28 谢谢。但下面两个例子感觉也不完全符合你给的定义啊,还有其他的规则吗?
"/home/foo/./.././bar" -> "/home/bar"
"/home/of/foo/../../bar/../../is/./here/." -> "/is/here" |
|
Q*******e 发帖数: 939 | 29 void foo(char *x)
{
printf("%d\n", *x);
}
int main(int argc, char **argv)
{
int a = 1;
foo(&a);
}
What's the output? |
|
i********m 发帖数: 332 | 30 For every object that is not a primitive type, it's passed by reference.
Only the primitive type and their wrapper are passed by value.
for example :
public void foo (Integer i) {
i = 9;
}
public static void main (String[] args) {
Integer i = new Integer (10);
foo(i);
System.out.println(i);
//The value is still 10 in i, not 9
} |
|
j*****s 发帖数: 189 | 31 我昨天和G的一个人 Phone Interveiw过了,代码的思路虽然很清晰,但是写的自我感
觉很渣,有好几处出了小毛病。会挂么?求保佑
有人问是什么题,因为挺简单的就没写出来,还是写出来和大家分享一下吧。
就是只能用一个putchar()函数,然后让实现一个函数,将指定地址的指定长度的数据
打印出来。
如"foo"->666a6a,输入的会是"foo"的地址,长度是6
18-> 00000012,输入的会是18的地址,长度是8 |
|
h****n 发帖数: 1093 | 32 我特意跑了一下程序
void foo(int *p1, int val1, int val2)
{
int j;
int *p2, *p3;
int * buf1 = (int*)malloc(sizeof(int)*20);
for(int j =0;j<20;j++)
buf1[j] = 1;
p2 = (int *)buf1;
//val1放到0x12fec8地址也就是当前p2指针指向的位置
*p2 = val1;
//把p1指向val1地址所指向的位置
p1 = (int *)*p2;
for (int i=1; i<10; i++)
{
p2 = (int *)buf1;
*p2 = val1;
p3 = (int *)*p2;
val1+=sizeof(int);
*p3 = val2;
}
printf("buf1:");
for(j =0;j<20;j++)
... 阅读全帖 |
|
f*****7 发帖数: 92 | 33 如题
C++中,Animal是定义好的class
Animal a
Animal* a
a.foo()
a->foo()
用对象变量 对象指针 访问类的函数或者成员变量
哪种方式更快呢?
求大牛讲解,谢谢您的时间~~
如果有权威链接给出,那再好不过了! |
|
w****a 发帖数: 710 | 34 二爷抬举了,我不是大牛、、、
我觉得singleton在C++里面有几个要注意的。别的语言我也不熟悉就不说了。
一个是跨dll的链接问题。如果是模板的singleton那种继承下来那种,比如
class foo: public singleton
这样的,继承下来的时候注意要显示的声明一下singleton的getInstance之类的函数。
否则跨dll可能会报链接错误。
一个是singleton的生命周期管理问题。就是注意初始化释放的顺序别弄乱了。有些大
型程序,比如说很多个manager,都是以singleton的形式搞的,初始化和释放顺序要自
己手动把握好。
一个是多线程下的singleton问题了。getInstance的时候搞个锁就行。
还有没有大牛有其他的建议? |
|
d**********x 发帖数: 4083 | 35 c++一般都用const vector&吧
或者用这玩意:
#include
using namespace std;
template
void foo(int (&arr)[N]) {
cout << N << endl;
cout << sizeof(arr) << endl;
}
int main() {
int a[10];
foo(a);
return 0;
} |
|
e*****e 发帖数: 1275 | 36 也赚点RP,顺便求bless
好奇怪的电面,居然是两个人同时开始。像一个teleconference, 更加操蛋的是,电话
还经常窜线,有人不停地在嗲嗲不休的说什么global finiancial turbulence.两个人
一个是三哥,另外一个是啥不太清楚,但是他老抱怨我说话的声音太小,听不见。我已
经尽量很大声了。
上来就问我啥是virtual,但是口音太重,老子居然根本就没有听明白,问了好多次,要
求他spell一下,也不肯,就在深深的沉默中。我觉得自己被深深的鄙视了,就苦苦思
考,到底是啥单词这么通俗这么易懂,我居然不知道?后来恍然大悟,问他是不是
virtual,他说是的。然后解释啥是virtul, 啥是polymorphism. 然后问我signature,
我说signature就是funcition name, number and type of parameter. 他不依,问我
return type 是不是,如果出现 int foo(), double foo()咋办。。。我说ambiguise
situation, c++不会让它过的。然后他得意洋洋的问我... 阅读全帖 |
|
e***s 发帖数: 799 | 37 请教各位大牛,面试时代码的规范,规范清晰的代码是不是会带来不少分数。我知道F
家很在意这个。
我抛砖引玉一下
比如 (Java)
if(a == b) return;
不如:
if(a == b){
return;
}
比如
foo = a + b * 2;
不如
foo = a + (b * 2);
比如
int a = 0, b = 1;
不如
int a = 0;
int b = 1; |
|
v**********m 发帖数: 5516 | 38 import javax.script.ScriptEngineManager;
import javax.script.ScriptEngine;
public class TestOfStringToMath {
public static void main(String[] args) throws Exception{
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine engine = mgr.getEngineByName("JavaScript");
String foo = "1 + 2 * 3 /4";
System.out.println(engine.eval(foo));
}
}
google到的,编译通过。
With JDK1.6, you can use the built-in Javascript engine.
http://stackoverflow.com/questions/3422673/evaluating-a-mat... 阅读全帖 |
|
v***d 发帖数: 42 | 39 跟FB同一周面的……今天催L的recruiter,催来了个悲剧……
总共电面2轮,onsite5轮 - 其中2轮coding,2轮resume check和project,1轮design
……算上电面,总共面了11道……题目顺序已打乱:
1. given the list {{1,1},2,{1,1}},返回10……因为,(four 1's at depth 2, one
2 at depth 1). 给定 {1,{4,{6}}} ,返回27……因为, (one 1 at depth 1, one 4
at depth 2, and one 6 at depth 3)
2. leetcode: traversal binary tree level by level
3. 给2个string,判断是否可以map. say (foo, abb) 这2个string是可以map的, f->a
, o->b. say (foo, sdf),是不可以map的……返回bool值
4. 给一个string,每10个letter一组,输出所有出现次数超过一次的strings with
length... 阅读全帖 |
|
c*****e 发帖数: 737 | 40 因为你的题目本来就是错的。
int* q = new int(10);
int* p = new int(10);
foo(p, q);
foo (q, p); |
|
a*****1 发帖数: 314 | 41 以前高通三哥 电面的题。 只记了大概。
1,const char * str = "hello"
str = "world"
*str = 'a'
问我 编译运行。 有没有错误,会在哪里出错。提示什么错误。
(2年前的题了。只记住个大概,就只这些基本的知识点。)
知识点:(印象里的)
const volatile static 意义
stack, heap,给变量定义问存储位置
inline function 作用意义,一般定义在哪里 , 跟 宏 的区别
判断Endianness 大端小端
计算字符,整数, 二进制 里 1 的个数 int foo(char a), int foo(int d)
偏系统一些的: 多线程多进程通信。 mutex semaphore 区别。 什么叫deadlock。
算法: 单链表比较多,逆序,删除,
二叉树,什么遍历输出的是有序的。 讲解过程。
|
|
j***m 发帖数: 6 | 42 1. 给两个类A和B
class A {
public void foo (A a) {
...
}
}
class B extends A {
public void foo (B b) {
...
}
}
问这么写会不会有问题
2. 关于Database的题,假如你执行
select * from employee
employee是一个table
但是返回错误说,这个table不存在什么的,但是现在已知存在这个table,问你可能是
什么原因。
完全没有思路,就说我也不知道。。。
3. 一种字母游戏这样的
给定四个位置 _,_,_,_
然后每个位置可以选5个candidates,然后问这些candidates最多可以组成多少个有效
的词,字典是给定的。
比如,
如果字典是 [cake, bike, fake]
我们可以这样选candidates
第一个位置可以选 b,c,f,e,d
第二个位置 i,a,o,p,e
第三个位置 k,m,w,q,a
第四个位置 e,g,h,k,l
那这些可以组成3个有效的词 cake, bike, fake.
但是如果,这样选每个位置的can... 阅读全帖 |
|
m*********a 发帖数: 3299 | 43 多谢了,我还不知道这样
当foo只有一个值的时候,可以v.insert(iterator_pos,value)或v.insert(iterator_
pos,foo(value));
我记得这是不鼓励用的class initiazation(这个叫法是对的吧)?
这个用法不是鼓励,用这种implicit的方法init class吗?
不知道为啥要引入这个功能
我觉得代码变得不清楚了 |
|
w******e 发帖数: 1621 | 44 第一个马公面试,回报版上
非cs phd, research 做的Machine Learning,校园面,无电面
第一轮,白小哥
(1)leetcode原题 best time to buy and sell stock(1 buy 1 sell的)
(2) bool foo()
如果最近1分钟foo被call了10次返回True,否者false
第二轮,阿三
(1) 假设你是一个node, 你的friend是你的neighbor, 每个friend离你给了一个距离(
非负)。friend还有friend, 要求返回从你开始 长度为n的所有path.
(2) leetcode原题 2d binary search
面完,三哥说校园排满,要求两周后去纽约继续2个面,一个senior management 一个
HR。出门接到三哥电话说下午3点半出现一个空,问要不要面了,我就说下午继续
第三轮,两个白女
一去以为2都是senior management,或者是1个是吗内急,一个是hr. 这轮就是拉家常
,我还想这马内积要水我不成,后来知道她俩都是hr.
第四轮白大叔(挂了)
真正的大... 阅读全帖 |
|
l********g 发帖数: 372 | 45 报点最近的面经,都是电面中的,攒点rp顺便求bless!
L家的:
1. Given two (dictionary) words as Strings, determine if they are isomorphic
. Two words are called isomorphic if the letters in one word can be remapped
to get the second word. Remapping a letter means replacing all occurrences
of it with another letter while the ordering of the letters remains
unchanged. No two letters may map to the same letter, but a letter may map
to itself.
Example:
Given "foo", "app"; returns true
we can map 'f' -> 'a' and 'o' -> 'p'
G... 阅读全帖 |
|
i****n 发帖数: 42 | 46 Here is my question:
class foo
{
int a;
int *b;
}
void doSth()
{
foo f;
}
void main()
{
doSth();
}
What will happen at run-time?
Thanks a lot. |
|
l****s 发帖数: 75 | 47 nothing happens.
a and b are not initialized.
try this:
#include
class foo
{
private:
int a;
int *b;
public:
void print()
{
std::cout << a << std::endl;
std::cout << &a << std::endl;
std::cout << b << std::endl;
//std::cout << *b << std::endl;
}
};
void doSth()
{
foo f;
f.print();
}
void main()
{
doSth();
std::cin.get();
} |
|
l*****a 发帖数: 14598 | 48 start from 0: it is bar/foo
start from 9: it is foo/bar
which include all words of L
what is your result?
the |
|
g********r 发帖数: 89 | 49 given "foo", "app"; returns true we can map f -> a and o->p
given "bar", "foo"; returns false we can't map both 'a' and 'r' to 'o'
given "ab", "ca"; returns true we can map 'a' -> 'b' and 'c' -> 'a'
记得lolhaha大牛说过一个hashmap的解法,具体怎么做呢? |
|
L*****1 发帖数: 34 | 50 昨天面试一家公司被问到一道multithread的问题,本身感觉不难,但是因为这方面经
验不多,想问问各位有没有什么好的解决办法。
给两个method:
void functionFoo() {
while(1){
System.out.print("Foo");
}
}
void functionBar() {
while(1) {
System.out.print("Bar");
}
}
然后两个thread,一个call functionFoo, 一个call functionBar,然后需要你修改这
两个方程来实现输出比如1000行"FooBar"
本人一开始直接用volatile,存一个flag,类似于static一样然后1的时候才输出Foo并
改为2,2的时候输出Bar并改为1。但是面试官说会有busy waiting,问怎么解决busy
waiting,尝试用wait()和notify()结果写出了deadlock。请问各位有什么java里面的
解决办法?谢谢! |
|