由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 问两道笔试题
相关主题
两道题两道面试题
A Google question分享两道面试题--求教高手
英语理解力太烂: 题目看不懂两道概率面试题
求解。。。问一个题目
[合集] 【讨论】两道非常难的Google面试题两道找最大submatrix的题?
关于search engine 和database的两道题求助!!!问两道微软题
电面后,hr发了两道题,请教高手两道brain teaser 题目
问两道逻辑题==!问两道bloomberg的题目
相关话题的讨论汇总
话题: ip话题: question话题: variable话题: your话题: contains
进入JobHunting版参与讨论
1 (共1页)
r***6
发帖数: 15
1
Question 1.
Given a variable guaranteed to contain either the value 1 or the value 2,
write a piece of code to make the variable equal to 1 if it contains 2, and
to make it equal to 2 if it contains 1.
Your code should be as fast and as short as possible.
Question 2.
Assuming that total and ip are declared correctly, what is wrong with the
following piece of code?
total = ip->size + (ip++)->size;
Please give your reasoning, and suggest an alternative, correct version.
a****o
发帖数: 15
2
Here is my thought for the first problem.
Assume the variable is m.
Then m = m xor 3

and

【在 r***6 的大作中提到】
: Question 1.
: Given a variable guaranteed to contain either the value 1 or the value 2,
: write a piece of code to make the variable equal to 1 if it contains 2, and
: to make it equal to 2 if it contains 1.
: Your code should be as fast and as short as possible.
: Question 2.
: Assuming that total and ip are declared correctly, what is wrong with the
: following piece of code?
: total = ip->size + (ip++)->size;
: Please give your reasoning, and suggest an alternative, correct version.

p*****2
发帖数: 21240
3
total = (ip++)->size+ip->size; ?
r****t
发帖数: 10904
4
1. ^3 或者 var = (var==1)?2:1
2. undefined.

and

【在 r***6 的大作中提到】
: Question 1.
: Given a variable guaranteed to contain either the value 1 or the value 2,
: write a piece of code to make the variable equal to 1 if it contains 2, and
: to make it equal to 2 if it contains 1.
: Your code should be as fast and as short as possible.
: Question 2.
: Assuming that total and ip are declared correctly, what is wrong with the
: following piece of code?
: total = ip->size + (ip++)->size;
: Please give your reasoning, and suggest an alternative, correct version.

r***6
发帖数: 15
5

是说ip++ undefined?

【在 r****t 的大作中提到】
: 1. ^3 或者 var = (var==1)?2:1
: 2. undefined.
:
: and

a********m
发帖数: 15480
6
for(...) a[i] = var1 + var2 - a[i];
1 (共1页)
进入JobHunting版参与讨论
相关主题
问两道bloomberg的题目[合集] 【讨论】两道非常难的Google面试题
两道面试题关于search engine 和database的两道题求助!!!
两道面试题: 概率和逻辑电面后,hr发了两道题,请教高手
问两道C++的面试题目问两道逻辑题==!
两道题两道面试题
A Google question分享两道面试题--求教高手
英语理解力太烂: 题目看不懂两道概率面试题
求解。。。问一个题目
相关话题的讨论汇总
话题: ip话题: question话题: variable话题: your话题: contains