由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - Epic Written Interview
相关主题
onsite遇到的几个面试题做题做得很郁闷,求指点
问个题?问两道字符串的题
aababccbc remove abc这个题目怎么做?
(附面经) cap-exempt H1B 到cap-subject H1B的问题像Leetcode: Text Justification这种边界条件多的题怎么办?
问个缺少逗号的数组赋值问题做了一道edit distance,讨论DP的初始化阶段
问一个facebook的电面find first diff of 2 strings
careerup 150里面的一道题。。ebay面经
说好得FG面经,回馈板上GGJJ求教一道关于string的Google面试题~~
相关话题的讨论汇总
话题: string话题: int话题: str话题: transpose话题: number
进入JobHunting版参与讨论
1 (共1页)
s******c
发帖数: 99
1
在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
时,快累死了。
数学题基本上就是脑筋急转弯,举几个例子
1. You have three kinds of magazines, all but two are Times, all but two are
Science, all but two are Nature. How many magazines in total do you have?
2. Only one of the answers is true
A. All of the below are true
B. All answers are true
C. One of the above is true
D. All of the above are true
E. None of the above are true
F. None of the above are true
3. You have two coins which sum up to 15 cents. One of them is not a dime.
What are the two coins (multiple choice)
A. Penny
B. Nickel
C. Dime
D. Quarter
E. Not possible
第二部分,是介绍一种高级语言,有点像lisp,没什么特别的,就按照它介绍的语法规
则来答
第三部分,编程题,一共四道题,实在没想到有这么多,鼓励自己坚持到最后,写完了
3道。没写上的那个题是最经典的电话按键排列组合题的变种,面之前没看,这个悔呀
1. You are given a telephone keyboard
0-0
1-1
2-ABC2
3-DEF3
4-GHI4
5-JKL5
6-MNO6
7-PQRS7
8-TUV8
9-WXYZ9
0-0
*-space
#-char separater
if you type "2", you will get 'A', that is
"2"-'A'
"22"-'B'
"222"-'C'
"2222"-'D'
However, the digits can repeated many times
"22222"-you get 'A' again
You can use "#" to separate characters, for example
"2#22", you get "AB"
However, you may also have consecutive different digits without separator: "
23"-'AD'
If you type "*", it means space.
You a given a sequence of digits, translate it into a text message
2. Basket ball hit rates
The hit rate of the basketball game is given by the number of hits divided
by the number of chances. For example, you have 73 chances but hit 15 times,
then your hit rate is 15/73=0.205 (keep the last 3 digits). On average, you
have 4.5 chances in each basketball game. Assume the total number of games
is 162. Write a function for a basketball player. He will input the number
of hits he has made, the number of chances he had, and the number of
remaining games. The function should return the number of future hits, so
that he can refresh his hit rate to 0.45
3. A Typist problem. 电话按键题的变种!一个打字员,10个手指,分别负责不同的
按键,
0-null
1-gftrvb
2-edc
3-wsx
4-qaz
5-null
6-yuhjnm
7-ik
8-ol
9-p
给你 9801,输出所有可能组合
pog
pof
pot
por
pov
pob
plg
plf
...
悔啊悔啊,面之前打算看电话按键题的,没看,没想到真考了……
4. String transpose
Transpose a string means re-sequencing a string
If you transpose string1 to string2, you can only swap the adjacent two
characters each time, until you get your target string.
For example, you want to transpose GUW to WUG, the steps are
GUW
GWU
WGU
WUG
Print all steps in string transpose
先把题放着看看,一会儿我再说我的答案
b*****c
发帖数: 1103
2
easy job, but no luck, sad
v***n
发帖数: 5085
3
楼主记忆力真好。。。这都能记得下来
p*i
发帖数: 411
4
我周一考……看来这个难度不大

【在 v***n 的大作中提到】
: 楼主记忆力真好。。。这都能记得下来
h********f
发帖数: 73
5
网上貌似有epic的题。。。。。
z****u
发帖数: 104
6
我只能预约到早晨8点的考试!考试中心最近也要20mile.
你们的考试都是几点开始的?
s******c
发帖数: 99
7
我也是8点考

【在 z****u 的大作中提到】
: 我只能预约到早晨8点的考试!考试中心最近也要20mile.
: 你们的考试都是几点开始的?

s******c
发帖数: 99
8
还是要好好准备一下的,每道题都要考虑细节。
递归那部分一定要好好看,一定是会考的,把输入电话按键给出字母排列那道题背下来。
还有就是字符串和数组的操作。
另外这个考试很看重时间,所以一定要尽快做完。

【在 p*i 的大作中提到】
: 我周一考……看来这个难度不大
b***e
发帖数: 383
9
多谢分享。
p*i
发帖数: 411
10
看到你说要背题,
no offense,我就不打击你了。
Good luck!

来。

【在 s******c 的大作中提到】
: 还是要好好准备一下的,每道题都要考虑细节。
: 递归那部分一定要好好看,一定是会考的,把输入电话按键给出字母排列那道题背下来。
: 还有就是字符串和数组的操作。
: 另外这个考试很看重时间,所以一定要尽快做完。

相关主题
问一个facebook的电面做题做得很郁闷,求指点
careerup 150里面的一道题。。问两道字符串的题
说好得FG面经,回馈板上GGJJ这个题目怎么做?
进入JobHunting版参与讨论
p*i
发帖数: 411
11
10点,on campus

【在 z****u 的大作中提到】
: 我只能预约到早晨8点的考试!考试中心最近也要20mile.
: 你们的考试都是几点开始的?

h********w
发帖数: 221
12
1. 6 magazines
2. E
3. BC
4. 电话按键,如2222, mode(4) , 0 is 2, 1 is A, 2 is B, 3 is C and so and,
Public phoneKey(String str){
String keystring="";
for(int i=0; i {

int count=0;
int key =0;

if(str.charAt(i) =='2'){

for(int j=0; str[j]!=2; j++)
{

++count;
}
key=count%4;

switch(key)
case 0:
key= 2; break;
case 1:
key = a; break;
.....
keystring+=key;
.....
}
累了,休息一下,
BTW, EPIC tnnd,2面都不给我,HR问了一堆HR的垃圾问题
......

}
return keystring;
}
s******c
发帖数: 99
13
第一题不对,一共就3本
编程第一题,你可以用来存储对应关系,如2->"ABC2",这样能更
简洁一些

【在 h********w 的大作中提到】
: 1. 6 magazines
: 2. E
: 3. BC
: 4. 电话按键,如2222, mode(4) , 0 is 2, 1 is A, 2 is B, 3 is C and so and,
: Public phoneKey(String str){
: String keystring="";
: for(int i=0; i: {
:
: int count=0;

n*s
发帖数: 752
14
4. telephone keyboard problem
import sys
map = {'0':'0','1':'1','2':'abc2','3':'def3','4':'ghi4','5':'jkl5','6':'mno6
','7':'pqrs7','8':'tuv8','9':'wxyz9','*':' ','#':'#'}
def translate():
print 'Please input from telephone keyboard:'
input = sys.stdin.readline().strip()
output = []
count = -1
prev = input[0]
for x in input:
if not (x in map.keys()):
return 'invalid input!'
if x == prev: # repeated input
if x == '*' or x == '0' or x == '1':
output.append(map[x])
else:
count += 1
else: # new input
if prev != '#':
size = len(map[prev])
output.append(map[prev][count %size])
count = 0
prev = x
# the very last char
if x != '#':
size = len(map[x])
output.append(map[x][count %size])
return ''.join(output)
if __name__ == '__main__':
print translate()
s******c
发帖数: 99
15
没事,确实答得不好,刚开始准备。
递归的问题我掌握得不好。有什么建议吗?

【在 p*i 的大作中提到】
: 看到你说要背题,
: no offense,我就不打击你了。
: Good luck!
:
: 来。

h********w
发帖数: 221
16
喔,sorry, all but是除了..以外的意思,

【在 s******c 的大作中提到】
: 第一题不对,一共就3本
: 编程第一题,你可以用来存储对应关系,如2->"ABC2",这样能更
: 简洁一些

n*s
发帖数: 752
17
4. string transpose
import sys
def transpose(input,i):
mystr = list(input)
mystr[i],mystr[i+1] = mystr[i+1],mystr[i]
return ''.join(mystr)
def str_transpose():
print 'input two strings, separated by blank:'
a, b = sys.stdin.readline().split()
size = len(a)
if size != len(b) or sorted(a) != sorted(b):
return 'no way!'
next = [b]
parent = {b:None}
idx = size -1
notFound = True
while notFound:
newstr = []
for x in next:
for i in xrange(idx):
tmp = transpose(x,i)
if not (tmp in parent.keys()):
parent[tmp] = x
newstr.append(tmp)
if tmp == a:
notFound = False
break
next = newstr
output = [a,'\n']
while parent[tmp] != None:
tmp = parent[tmp]
output += tmp
output += '\n'
return ''.join(output)
if __name__ == '__main__':
print str_transpose()

important
are

【在 s******c 的大作中提到】
: 在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
: 语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
: Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
: 时,快累死了。
: 数学题基本上就是脑筋急转弯,举几个例子
: 1. You have three kinds of magazines, all but two are Times, all but two are
: Science, all but two are Nature. How many magazines in total do you have?
: 2. Only one of the answers is true
: A. All of the below are true
: B. All answers are true

b***e
发帖数: 383
18
第二题有点不懂。
player总共有 4.5*162 = 729 次chance.
要使得 hit rate = 0.45, 那么总共的hit数是 729* 0.45 = 328.05.
如果知道目前的hit数,,那么后面的比赛只需要再有 328.05 - hits 就可以了。
那么输入 the number of chances he had, and the number of
remaining games 就没有任何的意义。
或者我们不知道player有多少次chance, 那么,而我们知道the number of (hits) he
has made, the number of (chances) he had, and the number of remaining
(games
).
如果这样,是不是解出这样的方程就可以了?
(hits + X) /(chances + games * 4.5) = 0.45
s******c
发帖数: 99
19
4.5次chance是个平均值,是帮你预测未来的情况的,以前的情况已经发生了,就不能
用4.5*162了。
后面那个公式是对的

he

【在 b***e 的大作中提到】
: 第二题有点不懂。
: player总共有 4.5*162 = 729 次chance.
: 要使得 hit rate = 0.45, 那么总共的hit数是 729* 0.45 = 328.05.
: 如果知道目前的hit数,,那么后面的比赛只需要再有 328.05 - hits 就可以了。
: 那么输入 the number of chances he had, and the number of
: remaining games 就没有任何的意义。
: 或者我们不知道player有多少次chance, 那么,而我们知道the number of (hits) he
: has made, the number of (chances) he had, and the number of remaining
: (games
: ).

b***e
发帖数: 383
20

多谢回复。

【在 s******c 的大作中提到】
: 4.5次chance是个平均值,是帮你预测未来的情况的,以前的情况已经发生了,就不能
: 用4.5*162了。
: 后面那个公式是对的
:
: he

相关主题
像Leetcode: Text Justification这种边界条件多的题怎么办?ebay面经
做了一道edit distance,讨论DP的初始化阶段求教一道关于string的Google面试题~~
find first diff of 2 stringsF电面
进入JobHunting版参与讨论
s******c
发帖数: 99
21
在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
时,快累死了。
数学题基本上就是脑筋急转弯,举几个例子
1. You have three kinds of magazines, all but two are Times, all but two are
Science, all but two are Nature. How many magazines in total do you have?
2. Only one of the answers is true
A. All of the below are true
B. All answers are true
C. One of the above is true
D. All of the above are true
E. None of the above are true
F. None of the above are true
3. You have two coins which sum up to 15 cents. One of them is not a dime.
What are the two coins (multiple choice)
A. Penny
B. Nickel
C. Dime
D. Quarter
E. Not possible
第二部分,是介绍一种高级语言,有点像lisp,没什么特别的,就按照它介绍的语法规
则来答
第三部分,编程题,一共四道题,实在没想到有这么多,鼓励自己坚持到最后,写完了
3道。没写上的那个题是最经典的电话按键排列组合题的变种,面之前没看,这个悔呀
1. You are given a telephone keyboard
0-0
1-1
2-ABC2
3-DEF3
4-GHI4
5-JKL5
6-MNO6
7-PQRS7
8-TUV8
9-WXYZ9
0-0
*-space
#-char separater
if you type "2", you will get 'A', that is
"2"-'A'
"22"-'B'
"222"-'C'
"2222"-'D'
However, the digits can repeated many times
"22222"-you get 'A' again
You can use "#" to separate characters, for example
"2#22", you get "AB"
However, you may also have consecutive different digits without separator: "
23"-'AD'
If you type "*", it means space.
You a given a sequence of digits, translate it into a text message
2. Basket ball hit rates
The hit rate of the basketball game is given by the number of hits divided
by the number of chances. For example, you have 73 chances but hit 15 times,
then your hit rate is 15/73=0.205 (keep the last 3 digits). On average, you
have 4.5 chances in each basketball game. Assume the total number of games
is 162. Write a function for a basketball player. He will input the number
of hits he has made, the number of chances he had, and the number of
remaining games. The function should return the number of future hits, so
that he can refresh his hit rate to 0.45
3. A Typist problem. 电话按键题的变种!一个打字员,10个手指,分别负责不同的
按键,
0-null
1-gftrvb
2-edc
3-wsx
4-qaz
5-null
6-yuhjnm
7-ik
8-ol
9-p
给你 9801,输出所有可能组合
pog
pof
pot
por
pov
pob
plg
plf
...
悔啊悔啊,面之前打算看电话按键题的,没看,没想到真考了……
4. String transpose
Transpose a string means re-sequencing a string
If you transpose string1 to string2, you can only swap the adjacent two
characters each time, until you get your target string.
For example, you want to transpose GUW to WUG, the steps are
GUW
GWU
WGU
WUG
Print all steps in string transpose
先把题放着看看,一会儿我再说我的答案
b*****c
发帖数: 1103
22
easy job, but no luck, sad
v***n
发帖数: 5085
23
楼主记忆力真好。。。这都能记得下来
h********f
发帖数: 73
24
网上貌似有epic的题。。。。。
s******c
发帖数: 99
25
我也是8点考

【在 z****u 的大作中提到】
: 我只能预约到早晨8点的考试!考试中心最近也要20mile.
: 你们的考试都是几点开始的?

s******c
发帖数: 99
26
还是要好好准备一下的,每道题都要考虑细节。
递归那部分一定要好好看,一定是会考的,把输入电话按键给出字母排列那道题背下来。
还有就是字符串和数组的操作。
另外这个考试很看重时间,所以一定要尽快做完。

【在 p*i 的大作中提到】
: 我周一考……看来这个难度不大
b***e
发帖数: 383
27
多谢分享。
h********w
发帖数: 221
28
1. 6 magazines
2. E
3. BC
4. 电话按键,如2222, mode(4) , 0 is 2, 1 is A, 2 is B, 3 is C and so and,
Public phoneKey(String str){
String keystring="";
for(int i=0; i {

int count=0;
int key =0;

if(str.charAt(i) =='2'){

for(int j=0; str[j]!=2; j++)
{

++count;
}
key=count%4;

switch(key)
case 0:
key= 2; break;
case 1:
key = a; break;
.....
keystring+=key;
.....
}
累了,休息一下,
BTW, EPIC tnnd,2面都不给我,HR问了一堆HR的垃圾问题
......

}
return keystring;
}
s******c
发帖数: 99
29
第一题不对,一共就3本
编程第一题,你可以用来存储对应关系,如2->"ABC2",这样能更
简洁一些

【在 h********w 的大作中提到】
: 1. 6 magazines
: 2. E
: 3. BC
: 4. 电话按键,如2222, mode(4) , 0 is 2, 1 is A, 2 is B, 3 is C and so and,
: Public phoneKey(String str){
: String keystring="";
: for(int i=0; i: {
:
: int count=0;

n*s
发帖数: 752
30
4. telephone keyboard problem
import sys
map = {'0':'0','1':'1','2':'abc2','3':'def3','4':'ghi4','5':'jkl5','6':'mno6
','7':'pqrs7','8':'tuv8','9':'wxyz9','*':' ','#':'#'}
def translate():
print 'Please input from telephone keyboard:'
input = sys.stdin.readline().strip()
output = []
count = -1
prev = input[0]
for x in input:
if not (x in map.keys()):
return 'invalid input!'
if x == prev: # repeated input
if x == '*' or x == '0' or x == '1':
output.append(map[x])
else:
count += 1
else: # new input
if prev != '#':
size = len(map[prev])
output.append(map[prev][count %size])
count = 0
prev = x
# the very last char
if x != '#':
size = len(map[x])
output.append(map[x][count %size])
return ''.join(output)
if __name__ == '__main__':
print translate()
相关主题
上一道题给你们休息休息问个题?
求问一道算法题~aababccbc remove abc
onsite遇到的几个面试题(附面经) cap-exempt H1B 到cap-subject H1B的问题
进入JobHunting版参与讨论
s******c
发帖数: 99
31
没事,确实答得不好,刚开始准备。
递归的问题我掌握得不好。有什么建议吗?

【在 p*i 的大作中提到】
: 看到你说要背题,
: no offense,我就不打击你了。
: Good luck!
:
: 来。

h********w
发帖数: 221
32
喔,sorry, all but是除了..以外的意思,

【在 s******c 的大作中提到】
: 第一题不对,一共就3本
: 编程第一题,你可以用来存储对应关系,如2->"ABC2",这样能更
: 简洁一些

n*s
发帖数: 752
33
4. string transpose
import sys
def transpose(input,i):
mystr = list(input)
mystr[i],mystr[i+1] = mystr[i+1],mystr[i]
return ''.join(mystr)
def str_transpose():
print 'input two strings, separated by blank:'
a, b = sys.stdin.readline().split()
size = len(a)
if size != len(b) or sorted(a) != sorted(b):
return 'no way!'
next = [b]
parent = {b:None}
idx = size -1
notFound = True
while notFound:
newstr = []
for x in next:
for i in xrange(idx):
tmp = transpose(x,i)
if not (tmp in parent.keys()):
parent[tmp] = x
newstr.append(tmp)
if tmp == a:
notFound = False
break
next = newstr
output = [a,'\n']
while parent[tmp] != None:
tmp = parent[tmp]
output += tmp
output += '\n'
return ''.join(output)
if __name__ == '__main__':
print str_transpose()

important
are

【在 s******c 的大作中提到】
: 在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
: 语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
: Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
: 时,快累死了。
: 数学题基本上就是脑筋急转弯,举几个例子
: 1. You have three kinds of magazines, all but two are Times, all but two are
: Science, all but two are Nature. How many magazines in total do you have?
: 2. Only one of the answers is true
: A. All of the below are true
: B. All answers are true

b***e
发帖数: 383
34
第二题有点不懂。
player总共有 4.5*162 = 729 次chance.
要使得 hit rate = 0.45, 那么总共的hit数是 729* 0.45 = 328.05.
如果知道目前的hit数,,那么后面的比赛只需要再有 328.05 - hits 就可以了。
那么输入 the number of chances he had, and the number of
remaining games 就没有任何的意义。
或者我们不知道player有多少次chance, 那么,而我们知道the number of (hits) he
has made, the number of (chances) he had, and the number of remaining
(games
).
如果这样,是不是解出这样的方程就可以了?
(hits + X) /(chances + games * 4.5) = 0.45
s******c
发帖数: 99
35
4.5次chance是个平均值,是帮你预测未来的情况的,以前的情况已经发生了,就不能
用4.5*162了。
后面那个公式是对的

he

【在 b***e 的大作中提到】
: 第二题有点不懂。
: player总共有 4.5*162 = 729 次chance.
: 要使得 hit rate = 0.45, 那么总共的hit数是 729* 0.45 = 328.05.
: 如果知道目前的hit数,,那么后面的比赛只需要再有 328.05 - hits 就可以了。
: 那么输入 the number of chances he had, and the number of
: remaining games 就没有任何的意义。
: 或者我们不知道player有多少次chance, 那么,而我们知道the number of (hits) he
: has made, the number of (chances) he had, and the number of remaining
: (games
: ).

b***e
发帖数: 383
36

多谢回复。

【在 s******c 的大作中提到】
: 4.5次chance是个平均值,是帮你预测未来的情况的,以前的情况已经发生了,就不能
: 用4.5*162了。
: 后面那个公式是对的
:
: he

D****3
发帖数: 611
37

important
are
nice post.
答案呢

【在 s******c 的大作中提到】
: 在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
: 语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
: Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
: 时,快累死了。
: 数学题基本上就是脑筋急转弯,举几个例子
: 1. You have three kinds of magazines, all but two are Times, all but two are
: Science, all but two are Nature. How many magazines in total do you have?
: 2. Only one of the answers is true
: A. All of the below are true
: B. All answers are true

e********r
发帖数: 2352
38
在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
时,快累死了。
数学题基本上就是脑筋急转弯,举几个例子
1. You have three kinds of magazines, all but two are Times, all but two are
Science, all but two are Nature. How many magazines in total do you have?
3 books
2. Only one of the answers is true
A. All of the below are true
B. All answers are true
C. One of the above is true
D. All of the above are true
E. None of the above are true
F. None of the above are true
E
3. You have two coins which sum up to 15 cents. One of them is not a dime.
What are the two coins (multiple choice)
A. Penny
B. Nickel
C. Dime
D. Quarter
E. Not possible
B C
第二部分,是介绍一种高级语言,有点像lisp,没什么特别的,就按照它介绍的语法规
则来答
第三部分,编程题,一共四道题,实在没想到有这么多,鼓励自己坚持到最后,写完了
3道。没写上的那个题是最经典的电话按键排列组合题的变种,面之前没看,这个悔呀
1. You are given a telephone keyboard
0-0
1-1
2-ABC2
3-DEF3
4-GHI4
5-JKL5
6-MNO6
7-PQRS7
8-TUV8
9-WXYZ9
0-0
*-space
#-char separater
if you type "2", you will get 'A', that is
"2"-'A'
"22"-'B'
"222"-'C'
"2222"-'D'
However, the digits can repeated many times
"22222"-you get 'A' again
You can use "#" to separate characters, for example
"2#22", you get "AB"
However, you may also have consecutive different digits without separator: "
23"-'AD'
If you type "*", it means space.
You a given a sequence of digits, translate it into a text message
/*
* =========================================================================
============
1. You are given a telephone keyboard
0-0
1-1
2-ABC2
3-DEF3
4-GHI4
5-JKL5
6-MNO6
7-PQRS7
8-TUV8
9-WXYZ9
0-0
*-space
#-char separater
if you type "2", you will get 'A', that is
"2"-'A'
"22"-'B'
"222"-'C'
"2222"-'D'
However, the digits can repeated many times
"22222"-you get 'A' again
You can use "#" to separate characters, for example
"2#22", you get "AB"
However, you may also have consecutive different digits without separator: "
23"-'AD'
If you type "*", it means space.
You a given a sequence of digits, translate it into a text message
* =========================================================================
============
*/
#include
#include
#include
using namespace std;
void init(map &container)
{
pair temp;
temp.first = '0';
temp.second = "0";
container.insert(temp);//0-0
temp.first = '1';
temp.second = "1";
container.insert(temp);//1-1
temp.first = '2';
temp.second = "ABC2";
container.insert(temp);//2-ABC2
temp.first = '3';
temp.second = "DEF3";
container.insert(temp);//3-DEF3
temp.first = '4';
temp.second = "GHI4";
container.insert(temp);//4-GHI4
temp.first = '5';
temp.second = "JKL5";
container.insert(temp);//5-JKL5
temp.first = '6';
temp.second = "MNO6";
container.insert(temp);//6-MNO6
temp.first = '7';
temp.second = "PQRS7";
container.insert(temp);//7-PQRS7
temp.first = '8';
temp.second = "TUV8";
container.insert(temp);//8-TUV8
temp.first = '9';
temp.second = "WXYZ9";
container.insert(temp);//9-WXYZ9
temp.first = '*';
temp.second = " ";
container.insert(temp);//*-space
}
vector< pair > parse(string &str)
{
vector< pair > tempContainer;
char pre = '-';
int count = 0;
if(str.size() <= 0)
return tempContainer;
for(int i = 0; i < str.size(); i++)
{
if(str[i] != pre)
{
if(i > 0)
{
pair temp;
temp.first = pre;
temp.second = count;
tempContainer.push_back(temp);
}
pre = str[i];
count=1;
}
else
{
count++;
}
}
pair temp;
temp.first = pre;
temp.second = count;
tempContainer.push_back(temp);
//for(int i = 0; i < tempContainer.size(); i++)
//cout<
return tempContainer;
}
char convert(char key, int value, map &container)
{
string str;
str = container[key];
return str[(value-1)%str.size()];
}
string translate(string &str)
{
map container;
init(container);
vector< pair > tempContainer;
tempContainer = parse(str);
string result;
for(int i = 0; i < tempContainer.size(); i++)
{
if(tempContainer[i].first != '#')
{
result += convert(tempContainer[i].first, tempContainer[i].
second, container);
}
}
return result;
}
int main(int argc, char *argv[])
{
string str = "223#3345#23";
cout<<"Tralsate "< cout< return 0;
}
2. Basket ball hit rates
The hit rate of the basketball game is given by the number of hits divided
by the number of chances. For example, you have 73 chances but hit 15 times,
then your hit rate is 15/73=0.205 (keep the last 3 digits). On average, you
have 4.5 chances in each basketball game. Assume the total number of games
is 162. Write a function for a basketball player. He will input the number
of hits he has made, the number of chances he had, and the number of
remaining games. The function should return the number of future hits, so
that he can refresh his hit rate to 0.45
/*
* =========================================================================
============
2. Basket ball hit rates
The hit rate of the basketball game is given by the number of hits divided
by the number of chances. For example, you have 73 chances but hit 15 times,
then your hit rate is 15/73=0.205 (keep the last 3 digits). On average, you
have 4.5 chances in each basketball game. Assume the total number of games
is 162. Write a function for a basketball player. He will input the number
of hits he has made, the number of chances he had, and the number of
remaining games. The function should return the number of future hits, so
that he can refresh his hit rate to 0.45
* =========================================================================
============
*/
#include
using namespace std;
double getHit(int h, int c, int r)//h is the number of hit he had made, c is
the number of chances he had made, r is the number of remainning games
{
double rate;
rate = 0.45;//rate
//double total = 4.5 * 162;//total

return 0.45*(c+r*4.5) - h;
}
int main(int argc, char *argv[])
{
cout< return 0;
}
3. A Typist problem. 电话按键题的变种!一个打字员,10个手指,分别负责不同的
按键,
0-null
1-gftrvb
2-edc
3-wsx
4-qaz
5-null
6-yuhjnm
7-ik
8-ol
9-p
给你 9801,输出所有可能组合
pog
pof
pot
por
pov
pob
plg
plf
...
悔啊悔啊,面之前打算看电话按键题的,没看,没想到真考了……
/*
* =========================================================================
============
*
* Filename: typist.cpp
*
* Description:
*
* Version: 1.0
* Created: 10/13/2013 04:00:44 PM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =========================================================================
============
*/
#include
#include
#include
#include
#include
using namespace std;
void init(map &container)
{
pair temp;
temp.first = '1';
temp.second = "gftrvb";
container.insert(temp);
temp.first = '2';
temp.second = "edc";
container.insert(temp);
temp.first = '3';
temp.second = "wsx";
container.insert(temp);
temp.first = '4';
temp.second = "qaz";
container.insert(temp);
temp.first = '6';
temp.second = "yuhjnm";
container.insert(temp);
temp.first = '7';
temp.second = "ik";
container.insert(temp);
temp.first = '8';
temp.second = "ol";
container.insert(temp);
temp.first = '9';
temp.second = "p";
container.insert(temp);
}
string filter(string &str)
{
stringstream stream;
for(int i = 0; i < str.size(); i++)
if(str[i] != '0' && str[i] != '5')
stream< return stream.str();
}
void update(vector &scan, vector &temp)
{
scan[0]++;
for(int i = 0; i < scan.size()-1; i++)
{
if(scan[i] >= temp[i])
{
scan[i] %= temp[i];
scan[i+1]++;//round
}
}
}
void combination(string &str)
{
string strTemp;
strTemp = filter(str);
map container;//save the key and the values
init(container);//initialize the container
//save the character number that each key can take care
//save the string that each key can represent
vector temp;
vector strContainer;
for(int i = 0; i < strTemp.size(); i++)
{
temp.push_back(container[strTemp[i]].size());
strContainer.push_back(container[strTemp[i]]);
}
//empty string
if(temp.size() == 0)
return;
int total = 1;//total number of the combinations
for(int i = 0; i < temp.size(); i++)
total *= temp[i];
vector scan(temp.size(), 0);
//output all the combinations
for(int i = 0; i < total; i++)
{
for(int j = 0; j < scan.size(); j++)
{
cout< }
cout< update(scan, temp);
}
}
int main(int argc, char * argv[])
{
string str = "9801";
combination(str);
return 0;
}
4. String transpose
Transpose a string means re-sequencing a string
If you transpose string1 to string2, you can only swap the adjacent two
characters each time, until you get your target string.
For example, you want to transpose GUW to WUG, the steps are
GUW
GWU
WGU
WUG
Print all steps in string transpose
/*
* =========================================================================
============
*
* Filename: transpose.cpp
*
* Description:
*
* Version: 1.0
* Created: 10/13/2013 04:47:15 PM
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Organization:
*
* =========================================================================
============
*/
#include
#include
using namespace std;
//check if str1 can be transposed to str2
bool valid(string &str1, string &str2)
{
if(str1.size() != str2.size())
return false;
char array1[200], array2[200];//check the number for each character in
both strings, use the array to represent 126 characters in the ASCII table

for(int i = 0; i < 200; i++)
{
array1[i] = 0;
array2[i] = 0;
}
for(int i = 0; i < str1.size(); i++)
{
int index;
index = str1[i];
array1[index]++;
index = str2[i];
array2[index]++;
}
for(int i = 0; i < 200; i++)
{
if(array1[i] != array2[i])
return false;
}
return true;
}
int getPosition(char c, string str)//find the first position of c in str
{
for(int i = 0; i < str.size(); i++)
if(c == str[i])
return i;
return -1;
}
void move(string &str, int i, int t)//move the character at i to t
{
for(int k = i; k > t; k--)
{
std::swap(str[k], str[k-1]);
cout< }
}
void transpose(string &str1, string &str2)
{
if(!valid(str1, str2))
{
cout<<"Input strings are not valid"< return;
}
cout<<"Transpose: "< for(int i = 0; i < str2.size(); i++)
{
char target = str2[i];
int targetIndex = i;
int initialIndex = getPosition(target, str1);
if(initialIndex == -1)
{
cout<<"Can not find "< return;
}
//move character at initialIndex to targetIndex in str1
move(str1, initialIndex, targetIndex);
}
cout<<"Have done transpose"< }
int main(int argc, char *argv[])
{
string str1, str2;//transpose str1 to str2
str1 = "GUW";
str2 = "WUG";
transpose(str1, str2);
return 0;
}
先把题放着看看,一会儿我再说我的答案
e********r
发帖数: 2352
39
明天机考,刚翻出各位老大帖的之前的题,练一下手.

important
are

【在 e********r 的大作中提到】
: 在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
: 语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
: Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
: 时,快累死了。
: 数学题基本上就是脑筋急转弯,举几个例子
: 1. You have three kinds of magazines, all but two are Times, all but two are
: Science, all but two are Nature. How many magazines in total do you have?
: 3 books
: 2. Only one of the answers is true
: A. All of the below are true

1 (共1页)
进入JobHunting版参与讨论
相关主题
求教一道关于string的Google面试题~~问个缺少逗号的数组赋值问题
F电面问一个facebook的电面
上一道题给你们休息休息careerup 150里面的一道题。。
求问一道算法题~说好得FG面经,回馈板上GGJJ
onsite遇到的几个面试题做题做得很郁闷,求指点
问个题?问两道字符串的题
aababccbc remove abc这个题目怎么做?
(附面经) cap-exempt H1B 到cap-subject H1B的问题像Leetcode: Text Justification这种边界条件多的题怎么办?
相关话题的讨论汇总
话题: string话题: int话题: str话题: transpose话题: number