我碰见的几道面试题,有兴趣看看(题目篇讨论贴)

浏览:5253 发布日期:2013/11/23 分类:心情闲聊
我也不知道为什么面试官要给我英文的题目,如果有兴趣的就看看吧,如果我英文理解错误。欢迎指出来!sql语句的倒数第二题我不会。本测试共11题,第一部份共5题,可选择使用类C语言或者PHP语言完成;第二部份共5题,请使用标准SQL语言完成;
第三部分为综合测试,共1题,只需要写出实现思路记录。

本测试为开卷测试,可以查阅资料,寻求他人帮助

第一部份(基本编程测试)
=======================

注意:本部份测试不考查严格语法,只考查算法和编程思路以及编程规范!

1. Trimming Blanks from the Ends of a String
   Please write a function to remove the trailing whitespaces of a string.
   [CODE]   ### YOUR CODE GOES HERE ... ###
    
    代码:
        $str = '写出一个字符串,删除字符串尾部的空格   '; //思路:删除尾部空格,也就是字符串右边空格,PHP自带函数有rtrim
        
        echo rtrim($str);   //结果:$str = '写出一个字符串,删除字符串尾部的空格';
    
   [\CODE]

2. Floating-point arithmetic is not precise, please write a function to 
compare two floating-point
   numbers and return TRUE if they're equal when carried out to a certain 
number of decimal places.
   For Example:
   # equal ( NUM1, NUM2, ACCURACY ) : return TRUE if NUM1 and NUM2 are equal 
to ACCURACY number of
   decimal places
   [CODE]   ### YOUR CODE GOES HERE ... ###

    代码:
        //思路:在PHP中,永远浮点数结果精确到最后一位,在平常总很少接触,但是在商城还有涉及到OA程序里面要严格注意这点
        //bccomp(参数1,参数2,小数位)这个是PHP数学函数中比较浮点数大小的函数

        $float1 = 200.2;
        $float2 = 200.2;

        checkFloat($float1,$float2,2)
        
        function checkFloat($float1,$float2,$num){
            if(bccomp($float1,$float2,2) === 0){
                return true
            }    
        }
        
   [\CODE]

3. Exacting Unique Elements from a Array
   Please write a function to eliminate duplicate values from a array.
   For Example:
   # ARRAY = ( 'This', 'is', 'a', 'array', 'with', 'a', 'duplicate', 
'element' )
   # should be return like : ARRAY = ( 'This', 'is', 'a', 'array', 'with', 
'duplicate', 'element' )
   [CODE]   ### YOUR CODE GOES HERE ... ###

    代码:
        $array = array('This', 'is', 'a', 'array', 'with', 'a', 'duplicate', 'element' );//删除数组中重复的value值,当2个值一样的时候,保留第一次出现的值,在php中有array_unique()函数能完成

        $newArray = array_unique($array);  
        var_dump($newArray);  //结果 $array = array('This', 'is', 'a', 'array', 'with', 'duplicate', 'element' );

   [\CODE]

4. Reversing a Array
   Please write a function to reverse a array.
   For Example:
   # ARRAY = ( 'Wajig', 'is', 'not', 'gijaW' )
   # REVERSED = ( 'gijaW', 'not', 'is', 'Wajig' )
   [CODE]   ### YOUR CODE GOES HERE ... ###

    代码:
        $array = array('Wajig', 'is', 'not', 'gijaW'); //反转函数,在PHP中有array_reverse()即可完成
        
        $newArray = array_reverse($array);  
        var_dump($newArray);  //结果:$array = array('gijaW','not','is','Wajig');
        
   [\CODE]

5. Analog a Record Data Type
   Please create a record data type and write a function to print records by 
given keys.
   For Example:
   # RECORD = {
   #         NAME => 'myname',
   #        AGE => 25,
   #        EMPNO => '10',
   #        SALARY => $1000,
   #        FAVCOLOR => ( 'Green', 'Red', 'Yellow', 'Blue' )
   # }
   # print RECORD{'SALARY'} if RECORD{'NAME'} equal 'myname'

   [CODE]   ### YOUR CODE GOES HERE ... ###

    代码:
        //1、先创建这个数组
         
        $array = array(
             'NAME' => 'myname',
              'AGE' => 25,
                         'EMPNO' => '10',
             'SALARY' => $1000, //在php中 没有定义这个变量就会出现NOTICE 错误 ,我就当作这个是字符串'$1000',也许是您不小心写误的!

             'FAVCOLOR' => array( 'Green', 'Red', 'Yellow', 'Blue' )
            
        );

        //2、条件:如果键名 'NAME' 等于 'myname' 把$array 键名是 'SALARY' 赋值给$data
            foreach($array as $k=>$v){
                if($k === 'NAME'){
                    if($v === 'myname'){
                        $data = $array['SALARY'];
                        }
                    }
                }

        //3、 打印$data变量
            var_dump($data);//结果是'$1000'

        
        
        
   [\CODE]

第二部份(数据库编程测试)
=========================

########### 测试表 ###########
表名:test
字段:
|name|age|empno|salary|manger|
记录:
|zhangsan|21|10|1000|hongliu|
|lisi|30|12|2500|sunqi|
|wangwu|28|12|2300|sunqi|
|zhaoliu|22|10|1500|hongliu|
|hongliu|35|10|2800|-|
|sunqi|29|12|3000|-|
#############################

6. Please write SQL to list all name, salary whose manager is 'hongliu'
   # Result:
   #   name        salary
   #   ----        ------
   #   zhangsan        1000
   #   zhaoliu        1500
   #   -----------------------

    答案:SELECT name,salary from test WHERE manger = 'hongliu';

7. Condition is same as <6>, output summary of salary and average of age
   # Result:
   #    sum_of_salary    average_of_age
   #    -------------    --------------
   #    2500        21.5
   #    ------------------------------
    
    答案:SELECT sum(salary),avg(age) from test ;
   

8. Please write SQL to list name and salary whose salary less than 2000 and 
add 500 for each
   # Result:
   #    before add
   #    name        salary
   #    ----           ------
   #    zhangsan    1000
   #    zhaoliu        1500
   #    ----------------------
   #    after add
   #    name        salary
   #    ----           ------
   #    zhangsan    1500
   #    ----------------------

    答案:1、UPDATE test set salary = salary + 500 WHERE salary < 2000;  //把小于2000的,每人+500
          2、select name,salary from test;  //因为您给出了要修改后的结果,并且字段只有2个,分别是name和salary。

9. Please write SQL to create a view same as table test but sort by name 
ASC, plus serial number according to sort
   result, just list serial number and name
   # Result:
   #    serial_no    name
   #    ---------    ----
   #    1        hongliu
   #    2        lisi
   #    3        sunqi
   #    4        wangwu
   #    5        zhangsan
   #    6        zhaoliu
   #    -----------------------

    答案:SELECT  name from test GROUP BY (name) ORDER BY name asc;//这个题目那个serial_no自增没弄过,所以这题打不出来

10. Please write SQL to delete record whose name is 'hongliu' and confirm 
correctly update other records (no
    cascade delete)
   # Result:
   # name    age    empno    salary    manger
   # ----    ---    -----    ------    ------
   # zhangsan    21    10    1000    -
   # lisi    30    12    2500    sunqi
   # wangwu    28    12    2300    sunqi
   # zhaoliu    22    10    1500    -
   # sunqi    29    12    3000    -
   # -----------------------------------------

    答案:
        方法1:    SELECT name,age,empno,salary,if(manger='hongliu','',manger) from  (SELECT name,age,empno,salary,manger from test where name != 'hongliu') AS tmp;//这个是SELECT 查询出来的条件 如果是DELETE的话 就要多一步

        方法2:
            步骤1、DELETC from test where name ='hongliu';//得到1个重新的表结果
            步骤2、UPDATE test set    manger = '' WHERE manger ='hongliu';

    
第三部份(综合能力测试)
=======================

11. 请设计一个方案测试全国各地访问公司服务器的最高速度
    第一:找网上测试速度的网站测试,例如http://www.webkaka.com/webCheck.aspx?url=http%3A%2F%2Fwww.baidu.com&sitesearch=0。
        
    
    第二:把弄到需要测试城市的代理服务器,然后用各个服务器去访问公司服务器的速度。
最佳答案
评论() 相关
后面还有条评论,点击查看>>