您的位置:知识库 » .NET技术

中软面试题-最新

作者: tomin  来源: 博客园  发布时间: 2010-07-29 15:36  阅读: 2547 次  推荐: 1   原文链接   [收藏]  

      中软的面试比较经典,也比较严格,一般有四轮,类似于微软的面试。中软面过以后,根据项目组,会推到美国微软那边运用live meeting & con-call 再面一次。以下是我的面试题及个人的小分析,拿出来和大家share一下。希望更多的人能过这个坎。如有什么问题,可以一起交流。直接进入主题:

 1. English communication. (sale yourself, project information, your interesting,and how to deal with problem    you encounter etc.)

 2.  the using of key words "new".

     Regarding this problem, you can refer to my other blog with this path: new . or you can get more information from internet.

3.Write a method which can remove the same unit from a Array which has been sorted.

//在排序好的数组中移除相同的元素
public int [] RemoveCommon(int [] a)
{
       
if (a.Length==0)
    {
        
return a;
    }            
    List 
<int> Result = new List<int>();
    
int i , j;
    i 
= j = 0;
    
int temp = a[0];

    
while (i < a.Length)
    {
        
if (a[i] != temp)
        {   
            j
++;     
            temp 
= a[i];
            Result.Add(temp);    
        }
        i
++;
    } 
    
// convert List to Array
    
//......
    return Result;            
}

4. Judge Triangle and write test case for your code.

判断一个三角形,如果是等边的返回1,等腰返回2,其他的返回3,不能构成三角形的返回 4。 再编写test case 测试
判断一个三角形,如果是等边的返回1,等腰返回2,其他的返回3,不能构成三角形的返回 4。 再编写test case 测试
public int Triangle(int a, int b, int c)
{           
    
if (a <= 0 || b <= 0 || c <= 0)
    {
        
return 4;
    }
    
int [] arry = new int [3] { a, b, c };
    Array.Sort(arry);
    
int min, mid, max;
    min 
= arry[0];
    mid 
= arry[1];
    max 
= arry[2];
    
if (max-mid<min)  // 注意:用这个去判断是否能构成三角形
    {
        
return 4;  //不能构成三角形
    }
    
if (min == max)
    {
        
return 1;  //等边
    }
    
else if ( mid==min || mid == max)
    {
        
return 2// 等腰
    }
    
else
        
return 3;   // 其他         
}

在这里,我最想提的就是这一题了,因为,我们知道,判断三角形,我们常用 两边之和大于第三边。但是,在这里,就不能用了。例如: a= int.MaxValue, b=int.MaxValue, c=int.MaxValue, 这时候三边肯定能构成三角形,但是,a+b 的和已经超过了int 型的最大值。造成内存溢出。 有人说,内存溢出 就是 0 或者负数,用这个不就可以判断吗?这个还真不行。你可以多写几个test case 试试。

Test case:

其他的普通的case,我就不写了,在这里就强调一下,边界值的问题(也就是常说的 临界值)。int.maxvalue, 0 etc.

5.Reverse string.

字符串反转,例如: string str="I love china", 反转后就是 str="china love I".
private char [] Convent(char [] str,int start, int end)
{
    
char temp;
    
int len = end - start;          
    
int i=0;
      
while(i<len/2)
      {
           temp = str[start+i];
           str[start +i] = str[end -- 1];
           str[end-i-1= temp;
           i++;
        }
    
return str;
}
public string Reverse(string str)
{
    
if (String.IsNullOrEmpty(str))
    {
        
return null;
    }
     
char [] objstr = str.ToCharArray(); ;
     
int length=objstr.Length;
     objstr = Convent(objstr,0,length);
     
int i = 0;
     
int start=0,end=0;
    
while (i < length)
    {                 
        
if (objstr[i] == ' '||i==length-1)
        {
            
if (i == length - 1)
            {
                end = i + 1;
            }
            
else
            {
                end = i;
            }
            objstr = Convent(objstr, start, end);
            start = end+1
         }
         i++;
    }
     
return new string(objstr);
}

6. Find the most width level in a tree and return the count of level, if there are many one, just return the nearest level. (it can be found in the internet)

寻找树的最宽层,并返回那层的层数(如有多个最宽层,返回离根节点最近的层数)
static int  M 10 //假设二叉树最多的层数
int Width(BinTree T)
 { 
  
int static n[M];//向量存放各层结点数
  int static i=1;
  
int static max=0;//最大宽度
  if(T)
   {
    
if(i==1//若是访问根结点
     { 
      n[i]++//第1层加1
      i++//到第2层
      if(T->lchild)//若有左孩子则该层加1
       n[i]++;
      
if(T->rchild)//若有右孩子则该层加1
       n[i]++;
     }
    
else
     { //访问子树结点
      i++//下一层结点数
      if(T->lchild)
       n[i]++;
      
if(T->rchild) 
       n[i]++;
     }
    
if(max<n[i])max=n[i];//取出最大值
     Width(T->lchild);//遍历左子树
    i--//往上退一层
    Width(T->rchild);//遍历右子树
   }
  
return max;
 }//算法结束

7. Implement the function: Int ConvertToInt(string num)

实现 Int ConvertToInt(string num)
public  int ConvertToInt(string num)
{          
    
int result=0;
    
int temp=0;
    
if (!string.IsNullOrEmpty(num))
    {
        
if (IsInteger(num))
        {
            
for (int i = 0; i < num.Length; i++)
            {
                temp = result;
                result = result * 10 + ((int)num[i] - 48); //0 的Asscall码 是48
                if (temp == result)
                    
continue;
            }
            
if (temp != result)
            {
                
throw new Exception("overflow");
            }
        }
       
    }         
    
return result;    
}
// 判断字符串是否是整数。
public bool IsInteger(string strIn)
{
    
bool bolResult = true;
    
if (strIn == "")
    {
        bolResult = false;
    }
    
else
    {
        
foreach (char Char in strIn)
        {
            
if (char.IsNumber(Char))
                
continue;
            
else
            {
                bolResult = false;
                
break;
            }
        }
    }
    
return bolResult;
}

  关于上面的判断字符串里转换后是否是整数,还有其他的方法:

判断是否是数字
public bool isnumeric(string str)
{
    
char[] ch = new char[str.Length];
    ch = str.ToCharArray();
    
for (int i = 0; i < ch.Length; i++)
    {
        
if (ch[i] < 48 || ch[i] > 57)
            
return false;
    }
    
return true;
}

8. Quick sort. (you can get it from internet)

快速排序
static public void Quicksort(int[] array, int begin, int end)
{
    
if (begin < 0 || end < 0 || begin > end)
        
return;
    
int left = begin, right = end, temp;
    temp 
= array[left];
    
while (right != left)
    {
        
while (temp < array[right] && right > left)
            right
--;
        
if (right > left)
        {
            array[left] 
= array[right];
            left
++;
        }
        
while (temp > array[left] && right > left)
            left
++;
        
if (right > left)
        {
            array[right] 
= array[left];
            right
--;
        }
    }
    array[right] 
= temp;
    Quicksort(array, right 
+ 1, end);
    Quicksort(array, begin, right 
- 1);
}

Ok, that is all.

那次面试比较久,接近四个小时。后面被推到微软那边面试,面试题,详见后面解析。 

1
0
标签:C#

.NET技术热门文章

    .NET技术最新文章

      最新新闻

        热门新闻