avatar
Epic Written Interview# JobHunting - 待字闺中
s*c
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
先把题放着看看,一会儿我再说我的答案
avatar
b*c
2
easy job, but no luck, sad
avatar
v*n
3
楼主记忆力真好。。。这都能记得下来
avatar
p*i
4
我周一考……看来这个难度不大

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

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

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

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

来。

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

avatar
p*i
11
10点,on campus

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

avatar
h*w
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;
}
avatar
s*c
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;

avatar
n*s
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()
avatar
s*c
15
没事,确实答得不好,刚开始准备。
递归的问题我掌握得不好。有什么建议吗?

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

avatar
h*w
16
喔,sorry, all but是除了..以外的意思,

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

avatar
n*s
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

avatar
b*e
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
avatar
s*c
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
: ).

avatar
b*e
20

多谢回复。

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

avatar
s*c
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
先把题放着看看,一会儿我再说我的答案
avatar
b*c
22
easy job, but no luck, sad
avatar
v*n
23
楼主记忆力真好。。。这都能记得下来
avatar
h*f
24
网上貌似有epic的题。。。。。
avatar
s*c
25
我也是8点考

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

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

【在 p*i 的大作中提到】
: 我周一考……看来这个难度不大
avatar
b*e
27
多谢分享。
avatar
h*w
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;
}
avatar
s*c
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;

avatar
n*s
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()
avatar
s*c
31
没事,确实答得不好,刚开始准备。
递归的问题我掌握得不好。有什么建议吗?

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

avatar
h*w
32
喔,sorry, all but是除了..以外的意思,

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

avatar
n*s
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

avatar
b*e
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
avatar
s*c
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
: ).

avatar
b*e
36

多谢回复。

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

avatar
D*3
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

avatar
e*r
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<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<return;
}
cout<for(int i = 0; i < str2.size(); i++)
{
char target = str2[i];
int targetIndex = i;
int initialIndex = getPosition(target, str1);
if(initialIndex == -1)
{
cout<return;
}
//move character at initialIndex to targetIndex in str1
move(str1, initialIndex, targetIndex);
}
cout<}
int main(int argc, char *argv[])
{
string str1, str2;//transpose str1 to str2
str1 = "GUW";
str2 = "WUG";
transpose(str1, str2);
return 0;
}
先把题放着看看,一会儿我再说我的答案
avatar
e*r
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

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。