年32。 个人期望:合理待遇+公积金,拒外包希望做长期运营类项目。 邮箱: [email protected] 腾讯圣经题(上帝让在圣经中查词,因为不知道圣经到底多大,用了日志文件替代圣经): <? /** * Tencent 圣(神)经题 * @version 1.01 * @author 子悟 * @description 缺陷:单线程很慢 ,不如按行读取后放入数据库,将优化工作交给数据库实现 */ //ini_set('max_execution_time','500'); set_time_limit(500); function search($str){ $start = memory_get_usage(); $startTime = microtime(true); $fo=fopen('access_log','r'); $lineNumber=1; $searchResult=''; while($lineStr = fgets($fo)){ //echo $lineNumber,':',$lineStr; //$result=strpos($lineStr,$str); $arr=explode(' ',$lineStr); $result=array_search($str,$arr); if($result !== false){ $searchResult .= 'row:'.$lineNumber.',clomun:'.($result+1)."<br/>"; } $lineNumber++; } fclose($fo); $mdiff=(memory_get_usage()-$start); $tdiff=microtime(true)-$startTime; if($searchResult){ return $searchResult . "[$mdiff B][$tdiff ms]"; }else{ return 'sorry!can\'t found it!'."[$mdiff B][$tdiff ms]"; } } /*使用方法:传key参数*/ echo search($_GET['key']);
![]() | 1 robotdiy 2015-03-09 12:13:00 +08:00 php实现:输出 10,000 以内的三生素数,以换行符分隔。 |
![]() | 2 overflow 2015-03-09 12:31:20 +08:00 代码写得真的有点差 |
![]() | 5 RemRain 2015-03-09 13:25:02 +08:00 ``` $startTime = microtime $fo=fopen 'row:'.$lineNumber $searchResult . "[$mdiff B][$tdiff ms]" 'row:' "<br/>" ``` |
![]() | 6 RemRain 2015-03-09 13:33:06 +08:00 运行结果: /tmp/php $ php e.php PHP Notice: Undefined index: key in /private/tmp/php/e.php on line 37 Notice: Undefined index: key in /private/tmp/php/e.php on line 37 PHP Warning: fopen(access_log): failed to open stream: No such file or directory in /private/tmp/php/e.php on line 13 Warning: fopen(access_log): failed to open stream: No such file or directory in /private/tmp/php/e.php on line 13 PHP Warning: fgets() expects parameter 1 to be resource, boolean given in /private/tmp/php/e.php on line 16 Warning: fgets() expects parameter 1 to be resource, boolean given in /private/tmp/php/e.php on line 16 PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /private/tmp/php/e.php on line 26 Warning: fclose() expects parameter 1 to be resource, boolean given in /private/tmp/php/e.php on line 26 sorry!can't found it![1664 B][0.00013899803161621 ms] |
![]() | 7 lbp0200 2015-03-09 13:47:34 +08:00 mysql烹饪指南里有这个例子哈 |
![]() | 8 RemRain 2015-03-09 13:56:54 +08:00 ![]() 除了等号、点号左右空格不一致、单双引号混用、文件操作未作异常处理外的其他槽点: 1. 起始标记没用 <?php 导致很多环境下无法正常执行,而是直接打印出代码 2. 直接修改了运行时间,而且写出魔鬼数字,未作说明。执行后也没有还原,真 require 这个文件就惨了 3. 无用代码(被注释的部分)没有删除 4. search 函数返回的居然是提示字符串 5. 唯一一句英文提示,句首字母未大写,而且有语法错误 6. 函数内变量命名居然有 startTime, fo, arr, mdiff 各种风格,且很多变量容易混淆,如:start, startTime, result, searchResult 同意 @overflow 的观点 |
![]() | 9 loveyu 2015-03-09 14:14:57 +08:00 via Android 感觉我代码风格差不多,咋办 |
10 neutrino 2015-03-09 14:27:54 +08:00 上次说找不到php的那个谁来着。。 |
![]() | 11 haiyang416 2015-03-09 14:31:56 +08:00 via Android 话说我也准备找。 但是看到楼主发的几个求职帖,我真替楼主着急,要用点心啊。 |
![]() | 12 thanksir 2015-03-09 15:06:21 +08:00 我觉得楼主应该把简历亮出来 |
13 MarsWang 2015-03-09 16:12:45 +08:00 zhiming137 gmail 发分简历来? |
![]() | 14 overflow 2015-03-09 17:57:57 +08:00 |
![]() | 16 woshicixide 2015-03-09 19:08:56 +08:00 @RemRain 啥是魔鬼数学 |
![]() | 17 RemRain 2015-03-09 20:11:59 +08:00 ![]() |
20 lijinma 2015-03-10 09:54:48 +08:00 @woshicixide 应该叫魔术数字,实际代码中,应该用 const 代替魔术数字。 |
21 aksoft 2015-03-10 17:07:18 +08:00 考数学么...数学不好 |
22 aksoft 2015-03-10 17:07:37 +08:00 祝你早日找到工作.. |
![]() | 23 wlxwolves 2015-03-10 23:48:55 +08:00 楼主看看这个http://job.youzan.com/?user=konggu |
24 jinchun 2015-03-14 01:19:26 +08:00 @yd ``` $num_arr = range(1, 10000, 2); unset($num_arr[0]); $quote_arr = &$num_arr; $last_key = [[],[],[]]; foreach ($num_arr as $key => $value) { foreach ($quote_arr as $k => $v) { if($k < $key) continue; if($v != $value && ($v % $value == 0)) unset($quot_arr[$k]); } $last_key[0] = $last_key[1]; $last_key[1] = $last_key[2]; $last_key[2] = $key; if(!empty($last_key[0]) && $num_arr[$last_key[0]]+6 >= $num_arr[$last_key[2]]){ echo $num_arr[$last_key[0]],',',$num_arr[$last_key[1]],',',$num_arr[$last_key[2]],PHP_EOL; } } ``` 想了想,代码有点不够优美,还是贴出来,希望得到指教。 |
25 jinchun 2015-03-24 02:30:17 +08:00 @yd 看php手册看到FilterIterator这里, 试着用FilterTerator来解这道题,比10天前贴出来的自认为已经够快的代码快了20倍(11s -> 0.6s)。终归还是算法和知识积累不够。 |
![]() | 27 erhuabushuo 2015-04-08 11:07:39 +08:00 发个简历过来 erhuabushuo(at)gmail.com |
![]() | 28 sfards 2015-04-13 14:13:07 +08:00 不是是否已经入职,SFARDS期待你的简历[email protected] |
![]() | 29 surewings 2015-04-23 10:29:07 +08:00 http://www.jobtong.com/e/23117, 加入我们初创团队吧,有期权激励。我们在朝阳常营地铁站旁边 |
![]() | 30 mdwl 2015-04-30 16:07:38 +08:00 楼主,我是不是来晚了,上海的工作考虑吗? |