微软笔试面试题

微软亚洲技术支持中心

1. 进程(Process)和线程(Thread)的差别
2. 堆(Heap)与栈(stack)的差别
3. Windows是如何管理内存的
4. 介绍.Net和.Net的安全性
5. 客户端如何访问.Net组件实现Web Service
6. C/C++编译器中虚表是如何完成的
7. 谈谈COM的线程模型, 然后讨论进程内/外组件的差别
8. 谈谈IA32下的分页机制
9. 给两个变量,如何找出一个带环单链表中是什么地方出现环的
10. 在IA32中一共有多少种办法从用户态跳到内核态
11. 如果只想让程序有一个实例运行,不能运行两个,像winamp一样,只能开一个窗口,怎样实现
12. 如何截取键盘的响应,让所有的'a'变成'b'
13. Apartment在COM中有什么用,为什么要引入
14. 存储过程是什么,有什么用,有什么优点
15. Template有什么特点,什么时候用
16. 谈谈Windows DNA结构的特点和优点

微软亚洲工程院

基础题

1. regular expression不能描述的是?
a)两个连续偶数   b)两个连续奇数

2. 程序分析

int s(int v)
{
    
int count=0
       
int x=v;   
    
while (x) 
       {       
        count
++;
        x
=x&(x-1)  
      }     
    
return count;
}

s(9999)=?

3. 关于堆排序的东西,插入新的元素以后的结果
4. 关于C语言中,.h文件和.c文件之间的关系
5. 如果数据扩大两倍,是向左,还是向右移动几位的问题
6. 对二叉排序数,以什么输出(前序,中序,还是后续)输出,是排列
7. 一个顺序为 1,2,3,4,5,6 的栈,依次进入一个队列,然后再进栈, 顺序是什么?
8. 关于数组指针的的题目
9. 在编写代码是查找错误好还是用testing找好?
10. 好像是说编译器可以修改type error的好处或不好。

程序设计部分

1 Translate MIPS assembly code into a function in C/C++
* your code should be concise
* no any GOTOs/pointers

MIPS code:

func:
li v0,0
li t0,0
l1:
add t1,a0,a0
lb t2,0(t1)
beq t2,zero,l3
bne t2,a1,l2
add v0,v0,1
l2:
add t0,t0,1
j l1
l3:
jr ra

(caller register: t0~t9,a0~a3,v0~v1; callee s0~s7,ra)
然后列出了指令表,li是赋值,lb是将字段后第一个寄存器内容个字节的内容复制到第二个寄存器,beq是等值转移ben是不等值转移,j是无条件转移,jr转移至寄存器标示的内容.

2. 实现数组的插入、查找、删除操作

arr为指向数组的指针
len为数组长度
count表示数组元素数目
出错返回-1

int insert(int* arr, size_t len, size_t count, int val)

返回插入的数组索引
插入后要求对数组排序
出错处理

int search(int* arr, size_t len, size_t count, int val)

要求返回所找到的元素
出错处理

int remove(int* arr, size_t len, size_t count, int val)
要求返回删除的元素值
出错处理

测试部分

1. 你被分配到Internet Explorer研发部,(从核心到界面什么都可以).你如何设计,开发和测试它?
2. 给你个DVD,你应当如何测试它,如果你的时间极其有限,你会测试什么?为什么?
3. 给你一个字符比较函数strCmp(const char* string1,const char* string2)以及其返回值表明的意义,(>0,==0,<0),设计测试case
4. 一段字符串复制程序,指出其存在的错误和潜在缺陷

最后是个论述题目,只有这个题目是要用英文作答的,上面的都可以用Chinese

1) 问的是你在过去一年里做出过什么样的重要决定,你为什么做出这样的决定,这个决定对你的影响,你达到你作决定时期望的目标了没.有什么收获.
2) 问的是你在过去一年里遇到什么样的问题,你如何解决的,是和别人解决的还是自己解决的?你达到你作决定时期望的目标了没,有什么收获。

微软亚洲工程院笔试题

1. 找Bug

int CopyStringCount(const char* Str)
{
    
int nCount = 0;
    
char* pBuffer;
    pBuffer 
= new char[_MAX_PATH];
    strcpy(pBuffer,Str);
    
while(;pBuffer ;pBuffer++)
        
if(pBuffer == '\\') nCount ++;
    
return nCount;
}

2. 写输出

void foo(int p1[])
{
    
*p1 += 5;
}

void bar(int p2[])
{
    p2[
1= 15;
}

void main()
{
    
int a[]={3,4,5};
    
int b[]={3,4,5};
    
int *p2;
    p2
=&a[1];
    bar(p2);
    printf(
"%i %i %i\n",a[0],a[1],a[2]);
    p2
=&b[0];
    p2
++;
    foo(p2);
    bar(p2);
    printf(
"%i %i %i\n",b[0],b[1],b[2]);

微软亚洲工程院2004年第二轮笔试题

1. 找错

struct S 
{
    
int i;
    
int * p;
};
void main()
{
    S s;
    
int * p = &s.i;
    p[
0= 4;
    p[
1= 3;
    s.p 
= p;
    s.p[
1= 1;
    s.p[
0= 2;
}

程序会在哪一行死掉

2.

int CalcMean(int i)

    
static int s, c;
    s
+=i; c++;
    
return s/c;
}

求CalcMeas( CalcMeas(3) )=?

3.

int calc(int a,int b)
{
    
if(a >= b)
        
return (a==b)?a:b;
    
else
        
return a+b+calc(++a,--b);
}

求calc(1,5)等于?

Mircosoft面试题

1.2.4 IQ题(是填空的最后两题):

1、三个盒子,有一个有宝石,让你先选一个。然后主持人在剩下的盒子中打开一个空盒子(主持人知道宝石在哪个盒子里)。现在你有一次改变选择的机会。你改不改?

2、
abcdef*2=cdefab
cdefab*2=efabcd
每个字母代表一个数字
abcdef=?

2 编程题
(1) 写一个CircularQueue()
(2) 写一个Merge函数。把两个已排序的链表合并。两个链表一个是升序,一个是降序。

3 设计(可用中文)
设计一个密码对话框,用来保护用户的文件。
(1) 写出设计文档
(2) 写出各种功能的priority,以及为什么这样设定。
(3) 如果开发人员根据你的要求实现了这个对话框,你准备如何测试它?写出测试的各点。

4 测试(可用中文)
(1) 已知有一个函数,它的功能是将字符串转换成数字,你如何测试它?假设函数是这样的形式:atoi(char *,int*) 。请列出所有可能的测试案例。
(2) 现在有一个Web搜索引擎,它说它拥有了搜索的功能。你怎样测试它?请写出你想要测试的各个方面以及方法。

5 要用英文做答opening question
(1) 你曾经有过什么非常有创意的想法?最好是软件方面。
(2) 你想让开发者添加一个他认为不重要的功能,你会怎么做?英文是:
How would you convince a developer to add a featurethat the developer does not view as importart?


Microsoft程序员常用面试题

1.链表和数组的区别在哪里? 
2.编写实现链表排序的一种算法。说明为什么你会选择用这样的方法? 
3.编写实现数组排序的一种算法。说明为什么你会选择用这样的方法? 
4.请编写能直接实现strstr()函数功能的代码。 
5.编写反转字符串的程序,要求优化速度、优化空间。 
6.在链表里如何发现循环链接? 
7.给出洗牌的一个算法,并将洗好的牌存储在一个整形数组里。 
8.写一个函数,检查字符是否是整数,如果是,返回其整数值。(或者:怎样只用4行代码编写出一个从字符串到长整形的函数?) 
9.给出一个函数来输出一个字符串的所有排列。 
10.请编写实现malloc()内存分配函数功能一样的代码。 
11.给出一个函数来复制两个字符串A和B。字符串A的后几个字节和字符串B的前几个字节重叠。 
12.怎样编写一个程序,把一个有序整数数组放到二叉树中? 
13.怎样从顶部开始逐层打印二叉树结点数据?请编程。 
14.怎样把一个链表掉个顺序(也就是反序,注意链表的边界条件并考虑空链表)?


Mircosoft经典面试题智力题

1. 为什么下水道的井盖是圆的? 
答:因为圆井盖不会掉进下水道去,因为方井盖对角线明显长于边长,稍微角度不对就掉进去了,其他非圆形井盖也有这个问题。

2. 美国有多少辆车?(一个常见的类似问题是:美国有多少家加油站?) 
答:大约一亿辆车,算上公司的车,差不多平均每个家庭一辆车。

3. 美国有多少个下水道井盖? 
答:缺少数据,比如美国公路总长度之类的数据

4. 你让某些人为你工作了七天,你要用一根金条作为报酬。这根金条要被分成七块。你必须在每天的活干完后交给他们一块。如果你只能将这根金条切割两次,你怎样给这些工人分? 
答:1/7,2/7,4/7,第一天给1/7,第二天拿2/7换1/7

5. 一列火车以每小时15英里的速度离开洛杉矶,朝纽约进发。另外一列火车以每小时20英里的速度离开纽约,朝洛杉矶进发。如果一只每小时飞行25英里的鸟同时离开洛杉矶,在两列火车之间往返飞行,请问当两列火车相遇时,鸟飞了多远? 
答:用相对速度,距离是5L/7,L是两城市之间的距离

6. 假设一张圆盘像唱机上的唱盘那样转动。这张盘一半是黑色,一半是白色。假设你有数量不限的一些颜色传感器。要想确定圆盘转动的方向,你需要在它周围摆多少个颜色传感器?它们应该被摆放在什么位置?
答:两个就可以了,挨着放。有一个探测器测到变色,紧跟着另一个测到,过一段时间才有下一次。转盘从第一个测到变色的转向第二个。

7. 假设时钟到了12点。注意时针和分针重叠在一起。在一天之中,时针和分针共重叠多少次?你知道它们重叠时的具体时间吗?

8. 你有两个罐子,分别装着50个红色的玻璃球和50个蓝色的玻璃球。随意拿起一个罐子,然后从里面拿出一个玻璃球。怎样最大程度地增加让自己拿到红球的机会?利用这种方法,拿到红球的几率有多大? 
答:一个瓶子里装一个红球,其他都装到另一个瓶子里,取到红球的概率是149/198

9. 中间只隔一个数字的两个奇数被称为奇数对,比如17和19。证明奇数对之间的数字总能被6整除(假设这两个奇数都大于6)。现在证明没有由三个奇数组成的奇数对。 
答:题目有问题,应该把所有的“奇数”改为“质数”。原因是,质数对必然全是奇数,中间数字为偶数。指数对都不能被三整数,所以中间的数可以被三整除。得证连续三个奇数必有一个可以被三整除,大于6的质数全不能被三整数。所以不存在。

10. 一个屋子有一个门(门是关闭的)和3盏电灯。屋外有3个开关,分别与这3盏灯相连。你可以随意操纵这些开关,可一旦你将门打开,就不能变换开关了。确定每个开关具体管哪盏灯。 
答:开两个开关,过一段时间关一个,进去,一个灯亮,两个灯灭,灭的灯有一个是热的。

11. 假设你有8个球,其中一个略微重一些,但是找出这个球的惟一方法是将两个球放在天平上对比。最少要称多少次才能找出这个较重的球? 
答:拿出六个球比,两次可解决

12. 假设你站在镜子前,抬起左手,抬起右手,看看镜中的自己。当你抬起左手时,镜中的自己抬起的似乎是右手。可是当你仰头时,镜中的自己也在仰头,而不是低头。为什么镜子中的影像似乎颠倒了左右,却没有颠倒上下? 
答:上下和左右的定义不同,上下是面对称的,左右是旋转对称的 (如果两只眼睛是长成一上一下就好了)

13. 你有4瓶药。每粒药丸的重量是固定的,不过其中有一瓶药受到了污染,药丸的重量发生了变化,每个药丸增加了一点重量。你怎样一下子测出哪瓶药是遭到污染的呢? 
答:如果确切知道那一点重量是多少,可以采取一种方法:第二个瓶取一粒,第三个瓶去两粒第四个瓶取三粒。称重之后可以计算出。 
如果不确切的知道,可以考虑使用三根绳子和三个滑轮。

14. 下面玩一个拆字游戏,所有字母的顺序都被打乱。你要判断这个字是什么。假设这个被拆开的字由5个字母组成: 
答:
1) 共有多少种可能的组合方式?   26^5(可重复),26*25*25*24*23*22(不可重复) 
2) 如果我们知道是哪5个字母,那会怎么样? 5! 
3) 找出一种解决这个问题的方法。 穷举试探法,把五个字母按权重排序,逐步变大序列权重,可保证完却探索。


15. 有4个女人要过一座桥。她们都站在桥的某一边,要让她们在17分钟内全部通过这座桥。这时是晚上。她们只有一个手电筒。最多只能让两个人同时过桥。不管是谁过桥,不管是一个人还是两个人,必须要带着手电筒。手电筒必须要传来传去,不能扔过去。每个女人过桥的速度不同,两个人的速度必须以较慢的那个人的速度过桥。 
答:
  第一个女人:过桥需要1分钟; 
  第二个女人:过桥需要2分钟; 
  第三个女人:过桥需要5分钟; 
  第四个女人:过桥需要10分钟。 
  比如,如果第一个女人与第4个女人首先过桥,等她们过去时,已经过去了10分钟。如果让第4个女人将手电筒送回去,那么等她到达桥的另一端时,总共用去了20分钟,行动也就失败了。怎样让这4个女人在17分钟内过桥?还有别的什么方法? 
    第一次1和2过桥,共用2分钟 
    1回来,共用3分钟 
    3和4过桥,共用13分钟 
    2回来,共用15分钟 
    1和2过桥,共用17分钟 
    1和2返回的次序可以相反 ,效果不变


16. 如果你有一个5夸脱的水桶和一个3夸脱的水桶,如何准确量出4夸脱的水? 
答:装满3,3倒入5,装满3,3倒满5,3中剩1夸脱。倒空5,将一夸脱倒入5,装满3,倒入 5即可。


17. 你有一袋糖,有红色的,蓝色的,绿色的。闭上眼睛,拿出两块颜色一样的糖,你需要拿多少次才能确保有两块颜色相同的? 
答:四次 (鸽笼原理)

18. 如果你有两个桶,一个装的是红色的颜料,另一个装的是蓝色的颜料。你从蓝色颜料桶里舀一杯,倒入红色颜料桶,再从红色颜料桶里舀一杯倒入蓝颜料桶。两个桶中红蓝颜料的比例哪个更高?通过算术的方式来证明这一点。 
答:算术的方式来证明这一点。 设桶是杯子容量的k倍。蓝倒入红一杯,红中蓝的比例是1/(k+1)。倒回一杯,红中蓝色比例不变。蓝中红色比例是(k/(k+1))/k=1/(k+1)。比例一样大

Microsoft Interview Questions

The following are actual questions from actual interviews conducted by Microsoft employees on the main campus. Microsoft Consultants are sometimes allowed to have a life, so questions asked of them during interviews don't really count and aren't listed.

The questions tend to follow some basic themes:


Riddles

  • Why is a manhole cover round?
  • How many cars are there in the USA? (A popular variant is "How many gas stations are there in the USA?")
  • How many manhole covers are there in the USA?
  • You've got someone working for you for seven days and a gold bar to pay them. The gold bar is segmented into seven connected pieces. You must give them a piece of gold at the end of every day. If you are only allowed to make two breaks in the gold bar, how do you pay your worker?
  • One train leaves Los Angeles at 15mph heading for New York. Another train leaves from New York at 20mph heading for Los Angeles on the same track. If a bird, flying at 25mph, leaves from Los Angeles at the same time as the train and flies back and forth between the two trains until they collide, how far will the bird have traveled?
  • Imagine a disk spinning like a record player turn table. Half of the disk is black and the other is white. Assume you have an unlimited number of color sensors. How many sensors would you have to place around the disk to determine the direction the disk is spinning? Where would they be placed?
  • Imagine an analog clock set to 12 o'clock. Note that the hour and minute hands overlap. How many times each day do both the hour and minute hands overlap? How would you determine the exact times of the day that this occurs?
  • You have two jars, 50 red marbles and 50 blue marbles. A jar will be picked at random, and then a marble will be picked from the jar. Placing all of the marbles in the jars, how can you maximize the chances of a red marble being picked? What are the exact odds of getting a red marble using your scheme?
  • Pairs of primes separated by a single number are called prime pairs. Examples are 17 and 19. Prove that the number between a prime pair is always divisible by 6 (assuming both numbers in the pair are greater than 6). Now prove that there are no 'prime triples.'
  • There is a room with a door (closed) and three light bulbs. Outside the room there are three switches, connected to the bulbs. You may manipulate the switches as you wish, but once you open the door you can't change them. Identify each switch with its bulb.
  • Suppose you had 8 billiard balls, and one of them was slightly heavier, but the only way to tell was by putting it on a scale against another. What's the fewest number of times you'd have to use the scale to find the heavier ball?
  • Imagine you are standing in front of a mirror, facing it. Raise your left hand. Raise your right hand. Look at your reflection. When you raise your left hand your reflection raises what appears to be his right hand. But when you tilt your head up, your reflection does too, and does not appear to tilt his/her head down. Why is it that the mirror appears to reverse left and right, but not up and down?
  • You have 4 jars of pills. Each pill is a certain weight, except for contaminated pills contained in one jar, where each pill is weight + 1. How could you tell which jar had the contaminated pills in just one measurement?
  • The SF Chronicle has a word game where all the letters are scrambled up and you have to figure out what the word is. Imagine that a scrambled word is 5 characters long:
    1. How many possible solutions are there?
    2. What if we know which 5 letters are being used?
    3. Develop an algorithm to solve the word.
  • There are 4 women who want to cross a bridge. They all begin on the same side. You have 17 minutes to get all of them across to the other side. It is night. There is one flashlight. A maximum of two people can cross at one time. Any party who crosses, either 1 or 2 people, must have the flashlight with them. The flashlight must be walked back and forth, it cannot be thrown, etc. Each woman walks at a different speed. A pair must walk together at the rate of the slower woman's pace.

    Woman 1: 1 minute to cross 
    Woman 2: 2 minutes to cross 
    Woman 3: 5 minutes to cross 
    Woman 4: 10 minutes to cross 

    For example if Woman 1 and Woman 4 walk across first, 10 minutes have elapsed when they get to the other side of the bridge. If Woman 4 then returns with the flashlight, a total of 20 minutes have passed and you have failed the mission. What is the order required to get all women across in 17 minutes? Now, what's the other way?

  • If you had an infinite supply of water and a 5 quart and 3 quart pail, how would you measure exactly 4 quarts?
  • You have a bucket of jelly beans. Some are red, some are blue, and some green. With your eyes closed, pick out 2 of a like color. How many do you have to grab to be sure you have 2 of the same?
  • If you have two buckets, one with red paint and the other with blue paint, and you take one cup from the blue bucket and poor it into the red bucket. Then you take one cup from the red bucket and poor it into the blue bucket. Which bucket has the highest ratio between red and blue? Prove it mathematically.

Algorithms

  • What's the difference between a linked list and an array?
  • Implement a linked list. Why did you pick the method you did?
  • Implement an algorithm to sort a linked list. Why did you pick the method you did? Now do it in O(n) time.
  • Describe advantages and disadvantages of the various stock sorting algorithms.
  • Implement an algorithm to reverse a linked list. Now do it without recursion.
  • Implement an algorithm to insert a node into a circular linked list without traversing it.
  • Implement an algorithm to sort an array. Why did you pick the method you did?
  • Implement an algorithm to do wild card string matching.
  • Implement strstr() (or some other string library function).
  • Reverse a string. Optimize for speed. Optimize for space.
  • Reverse the words in a sentence, i.e. "My name is Chris" becomes "Chris is name My." Optimize for speed. Optimize for space.
  • Find a substring. Optimize for speed. Optimize for space.
  • Compare two strings using O(n) time with constant space.
  • Suppose you have an array of 1001 integers. The integers are in random order, but you know each of the integers is between 1 and 1000 (inclusive). In addition, each number appears only once in the array, except for one number, which occurs twice. Assume that you can access each element of the array only once. Describe an algorithm to find the repeated number. If you used auxiliary storage in your algorithm, can you find an algorithm that does not require it?
  • Count the number of set bits in a number. Now optimize for speed. Now optimize for size.
  • Multiple by 8 without using multiplication or addition. Now do the same with 7.
  • Add numbers in base n (not any of the popular ones like 10, 16, 8 or 2 -- I hear that Charles Simonyi, the inventor of Hungarian Notation, favors -2 when asking this question).
  • Write routines to read and write a bounded buffer.
  • Write routines to manage a heap using an existing array.
  • Implement an algorithm to take an array and return one with only unique elements in it.
  • Implement an algorithm that takes two strings as input, and returns the intersection of the two, with each letter represented at most once. Now speed it up. Now test it.
  • Implement an algorithm to print out all files below a given root node.
  • Given that you are receiving samples from an instrument at a constant rate, and you have constant storage space, how would you design a storage algorithm that would allow me to get a representative readout of data, no matter when I looked at it? In other words, representative of the behavior of the system to date.
  • How would you find a cycle in a linked list?
  • Give me an algorithm to shuffle a deck of cards, given that the cards are stored in an array of ints.
  • The following asm block performs a common math function, what is it?
    cwd xor ax, dx
        sub ax, dx
  • Imagine this scenario: 
    I/O completion ports are communictaions ports which take handles to files, sockets, or any other I/O. When a Read or Write is submitted to them, they cache the data (if necessary), and attempt to take the request to completion. Upon error or completion, they call a user-supplied function to let the users application know that that particular request has completed. They work asynchronously, and can process an unlimited number of simultaneous requests. 
    Design the implementation and thread models for I/O completion ports. Remember to take into account multi-processor machines.
  • Write a function that takes in a string parameter and checks to see whether or not it is an integer, and if it is then return the integer value.
  • Write a function to print all of the permutations of a string.
  • Implement malloc.
  • Write a function to print the Fibonacci numbers.
  • Write a function to copy two strings, A and B. The last few bytes of string A overlap the first few bytes of string B.
  • How would you write qsort?
  • How would you print out the data in a binary tree, level by level, starting at the top?

Applications

  • How can computer technology be integrated in an elevator system for a hundred story office building? How do you optimize for availability? How would variation of traffic over a typical work week or floor or time of day affect this?
  • How would you implement copy-protection on a control which can be embedded in a document and duplicated readily via the Internet?
  • Define a user interface for indenting selected text in a Word document. Consider selections ranging from a single sentence up through selections of several pages. Consider selections not currently visible or only partially visible. What are the states of the new UI controls? How will the user know what the controls are for and when to use them?
  • How would you redesign an ATM?
  • Suppose we wanted to run a microwave oven from the computer. What kind of software would you write to do this?
  • What is the difference between an Ethernet Address and an IP address?
  • How would you design a coffee-machine for an automobile.
  • If you could add any feature to Microsoft Word, what would it be?
  • How would you go about building a keyboard for 1-handed users?
  • How would you build an alarm clock for deaf people?

Thinkers

  • How are M&Ms made?
  • If you had a clock with lots of moving mechanical parts, you took it apart piece by piece without keeping track of the method of how it was disassembled, then you put it back together and discovered that 3 important parts were not included; how would you go about reassembling the clock?
  • If you had to learn a new computer language, how would you go about doing it?
  • You have been assigned to design Bill Gates bathroom. Naturally, cost is not a consideration. You may not speak to Bill.
  • What was the hardest question asked of you so far today?
  • If MS told you we were willing to invest $5 million in a start up of your choice, what business would you start? Why?
  • If you could gather all of the computer manufacturers in the world together into one room and then tell them one thing that they would be compelled to do, what would it be?
  • Explain a scenario for testing a salt shaker.
  • If you are going to receive an award in 5 years, what is it for and who is the audience?
  • How would you explain how to use Microsoft Excel to your grandma?
  • Why is it that when you turn on the hot water in any hotel, for example, the hot water comes pouring out almost instantaneously?
  • Why do you want to work at Microsoft?
  • Suppose you go home, enter your house/apartment, hit the light switch, and nothing happens - no light floods the room. What exactly, in order, are the steps you would take in determining what the problem was?
  • Interviewer hands you a black pen and says nothing but "This pen is red."
posted @ 2011-04-14 23:16  心梦帆影  阅读(676)  评论(0编辑  收藏  举报