a*a
2 楼
thx
l*i
3 楼
不过作为中国人,我本能觉得中国人最美。中国人长得最decent,高贵,有气质,有内
涵。欧美人长得很肤浅,其实就是老祖宗眼里的野蛮人样子。
发信人: reversebell (青面瘦), 信区: Fashion
标 题: Re: 有没有和我一样,觉得混血儿不比亚洲人漂亮的?
发信站: BBS 未名空间站 (Sun Aug 22 17:38:07 2010, 美东)
如果现在最发达国家都在非洲,估计长成非洲状才是美的标准。。。
涵。欧美人长得很肤浅,其实就是老祖宗眼里的野蛮人样子。
发信人: reversebell (青面瘦), 信区: Fashion
标 题: Re: 有没有和我一样,觉得混血儿不比亚洲人漂亮的?
发信站: BBS 未名空间站 (Sun Aug 22 17:38:07 2010, 美东)
如果现在最发达国家都在非洲,估计长成非洲状才是美的标准。。。
x*0
4 楼
当年在电脑上写的面试题啊 好怀念
非recursion:
不停地找‘operation number number’ 的组合
recursion
类似的方法,不过找number的时候tricky一点。建立两个counter,一个数operator的
数量,一个数number的数量。当number的数量=operator+1,就可以切出来成为一个
number
非recursion:
不停地找‘operation number number’ 的组合
recursion
类似的方法,不过找number的时候tricky一点。建立两个counter,一个数operator的
数量,一个数number的数量。当number的数量=operator+1,就可以切出来成为一个
number
r*7
7 楼
用stack, 一个stack放数字 一个stack放符号。
如果数字那个stack size 达到2, 怎pop这两个数字 并且pop一个符号 进行运算。 得
到的值再放进数字的stack。
继续读数。
直到读完input 并且符号stack为空, return 数字stack pop的元素
如果数字那个stack size 达到2, 怎pop这两个数字 并且pop一个符号 进行运算。 得
到的值再放进数字的stack。
继续读数。
直到读完input 并且符号stack为空, return 数字stack pop的元素
z*q
8 楼
b1g1的东西可以要鱼漂马
r*7
9 楼
也可以这样 从后往前, 只需要一个stack, 先存 4, 再存3, 再存2. 遇到符号 则
pop两次。 然后和符号运算。 结果在放进stack 然后继续,直到没有输入。
wiki:
http://en.wikipedia.org/wiki/Polish_notation
pop两次。 然后和符号运算。 结果在放进stack 然后继续,直到没有输入。
wiki:
http://en.wikipedia.org/wiki/Polish_notation
u*o
11 楼
这题recursion比非recursion难写啊。。
L*e
13 楼
Recursive solution: 两头切不行吗?
l*s
14 楼
我一次你买过6平
c*1
15 楼
int reverse_polish(const char*& str) {
OpCode op = getOpCode(str);
int x = reverse_polish(str);
int y = reverse_polish(str);
return op.apply(x,y);
}
OpCode op = getOpCode(str);
int x = reverse_polish(str);
int y = reverse_polish(str);
return op.apply(x,y);
}
x*j
16 楼
有啊
r*7
17 楼
始终没想到 recursion, 求大神上code。。。
s*5
18 楼
从末尾开始找第一个operator,找到就把之后的两个数取出做运算,把结果放回原
string,再接着recusion。
string,再接着recusion。
c*1
19 楼
here is the correct version:
int reverse_polish(const char*& str) {
if (is_number(str)) return parse_nuber(str);
OpCode op = getOpCode(str);
int x = reverse_polish(str);
int y = reverse_polish(str);
return op.apply(x,y);
}
note there is no error check, and note str is passed as reference to const
char*, so that functions can read what it needs as well as forwarding the
pointer.
int reverse_polish(const char*& str) {
if (is_number(str)) return parse_nuber(str);
OpCode op = getOpCode(str);
int x = reverse_polish(str);
int y = reverse_polish(str);
return op.apply(x,y);
}
note there is no error check, and note str is passed as reference to const
char*, so that functions can read what it needs as well as forwarding the
pointer.
f*b
21 楼
mark
L*e
22 楼
试着用Java写了一个。还是不够简练。Have to use String array, otherwise cannot
push the result back to the original array.
public static int evaluate(String[] array, int from, int to){
// get first operator, backward
int j = to;
String s = array[j];
while (j >= from && !Operator.isOperator(s.charAt(0))){
s = array[--j];
}
// get operands
Operator op = Operator.getOperator(s.charAt(0));
int opIndex = j;
int a = Integer.valueOf(array[++j]);
int b = Integer.valueOf(array[++j]);
int result = op.apply(a, b);
// most-left operator, done
if (opIndex == 0){
return result;
}
// push result back
array[opIndex] = Integer.toString(result);
//copy remaining over
j++;
while (j <= to){
array[++opIndex]= array[j++];
}
return evaluate(array, from, opIndex);
}
@Test
public void testPolishNotationSimple(){
String[] array = {"-", "5", "*", "6", "7"};
int result = PolishNotation.evaluate(array, 0, array.length - 1);
assertEquals(result, -37);
}
@Test
public void testPolishNotationSimple2(){
String[] array = {"*", "+", "2", "3", "4"};
int result = PolishNotation.evaluate(array, 0, array.length - 1);
assertEquals(result, 20);
}
@Test
public void testPolishNotationComplex(){
String[] array = {"-", "*", "/", "15", "-", "7", "+", "1", "1", "3", "+"
, "2", "+", "1", "1"};
int result = PolishNotation.evaluate(array, 0, array.length - 1);
assertEquals(result, 5);
}
push the result back to the original array.
public static int evaluate(String[] array, int from, int to){
// get first operator, backward
int j = to;
String s = array[j];
while (j >= from && !Operator.isOperator(s.charAt(0))){
s = array[--j];
}
// get operands
Operator op = Operator.getOperator(s.charAt(0));
int opIndex = j;
int a = Integer.valueOf(array[++j]);
int b = Integer.valueOf(array[++j]);
int result = op.apply(a, b);
// most-left operator, done
if (opIndex == 0){
return result;
}
// push result back
array[opIndex] = Integer.toString(result);
//copy remaining over
j++;
while (j <= to){
array[++opIndex]= array[j++];
}
return evaluate(array, from, opIndex);
}
@Test
public void testPolishNotationSimple(){
String[] array = {"-", "5", "*", "6", "7"};
int result = PolishNotation.evaluate(array, 0, array.length - 1);
assertEquals(result, -37);
}
@Test
public void testPolishNotationSimple2(){
String[] array = {"*", "+", "2", "3", "4"};
int result = PolishNotation.evaluate(array, 0, array.length - 1);
assertEquals(result, 20);
}
@Test
public void testPolishNotationComplex(){
String[] array = {"-", "*", "/", "15", "-", "7", "+", "1", "1", "3", "+"
, "2", "+", "1", "1"};
int result = PolishNotation.evaluate(array, 0, array.length - 1);
assertEquals(result, 5);
}
相关阅读
Gucci的经典款哪里买便宜啊请问美国有裸钻卖吗陈坤你肿么了My earrings[合集] 爆一個加州住在scromento的猥瑣男!(有照片) (转载)发一个亚洲女生年龄的漫画帮忙选择一个swarovski的pendant悲剧了!穿了耳洞,但是第2天开始发红,怎么办?谁要买Victoria's secret的10刀discount bra?[合集] 女人只要不生孩子还是显年轻的求姐妹们推荐:去痣,湾区请教回国给妈妈得护肤产品还有American Apparel 50 买100的咚咚用什么使头发变软变柔顺?【参加活动】不知道这个算不算啊~请教粉饼求推荐一双罗马鞋[参加活动]Go Maxi!什么年轻十几岁 自己回国内母校看看参加活动maxi