• **面试题


    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)

    快速排序

    from:http://www.cnblogs.com/tomin/archive/2010/07/28/Interview_Chinasoft.htm

    注: 这里的题目和答案全是原文转载,多年前我也做过其中部分题。今天再次审视它们,我还能看到一些东西,不过发现参考答案有部分并不准确。

  • 相关阅读:
    P1082 同余方程
    P2678 跳石头
    P2827 蚯蚓
    P1351 联合权值
    P2822 组合数问题
    P3958 奶酪
    P2296 寻找道路
    P2661 信息传递
    平时问题总结
    平时总结
  • 原文地址:https://www.cnblogs.com/Langzi127/p/1787555.html
Copyright © 2020-2023  润新知