论坛首页 编程语言技术论坛

腾讯php程序员面试题目,供大家学习一下

浏览 42766 次
精华帖 (0) :: 良好帖 (3) :: 新手帖 (0) :: 隐藏帖 (6)
作者 正文
   发表时间:2011-03-30  
感觉最后一题就是一个hash table的问题, 用hash table实现起来应该很简单
0 请登录后投票
   发表时间:2011-04-16   最后修改:2011-04-16
不能用正则,否则时间复杂度就不符合题目要求了~~~~~~
PS:还有大家别把问题想复杂了~~~~

<?php

$word = $argv[1];

function search_bbe($handle, $word) 
{
    $line = 1;
    $column = 1;
    $compare = null;
    $local_arr = array();
    $word = strtoupper($word);
    while(!feof($handle)){
        $s = strtoupper(fgetc($handle));
        switch(ord($s))
        {
            case 65:    //A
            case 66:    //B
            case 67:    //C
            case 68:    //D
            case 69:    //E
            case 70:    //F
            case 71:    //G
            case 72:    //H
            case 73:    //I
            case 74:    //J
            case 75:    //K
            case 76:    //L
            case 77:    //M 
            case 78:    //N
            case 79:    //O 
            case 80:    //P
            case 81:    //Q
            case 82:    //R
            case 83:    //S
            case 84:    //T
            case 85:    //U
            case 86:    //V
            case 87:    //W
            case 88:    //X
            case 89:    //Y 
            case 90:    //Z
                //todo:
                if(is_null($compare))   $start = $column;
                $compare .= $s;
                break;
            case 10:
                //todo:
                if($word === $compare){
                    array_push($local_arr, $line . ',' . $start);
                }
                $line++;
                $column=1;
                $compare = null;
                break;
            default:
                //todo:
                if($word === $compare){
                    array_push($local_arr, $line . ',' . $start);
                }
                $compare = null;
        }//End Switch
        $column++;
    }
    return $local_arr;
}//End Function

$handle = fopen(dirname(__FILE__) . '/bbe.txt', 'r');
$local_arr = search_bbe($handle, $word);
fclose($handle);

print_r($local_arr);

0 请登录后投票
论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics