分享今天面试的三道题
公司名不说了。
一、模拟扑克发牌,有52张扑克牌,我们给它编号,从1,2,3...52。一共52张牌。请使用数组装载这些牌,然后再打乱顺序输出。比如:43,2,18,21...3。
二、公司要和QQ合作,提供接口给QQ,会发QQ号过来。请帮忙检测QQ好嘛的规则。如4323254,规则为:ABAB。5723723,规则为ABCABC。
三、假如我们现在要记录下网站中每一个flash小游戏被玩过多少次,每个游戏在一个单独的页面。
(a)请问在玩这些游戏的时候如何记录数据?
(b)如果计算出每个游戏被玩过多少次?(如果使用数据库的话,请写出SQL)
第二题我没答出来。请教下如何实现那个需求。
题量还不错,就三道,不过这些题考的貌似没啥针对性,比那些一写就要写2小时的好多了。
------解决方案--------------------
第二题思路:
对于每个qq,判断qq的前缀和后缀。树的长度从0 - strlen/2
如4323254
索引0开始的:
1位前缀:4,后缀3 不等
2位前缀:43 后缀23 不等
3位前缀的:432后缀325 不等
。。。
索引1开始的:
2前缀32 后缀32相等
计算长度最大的即可
$qqNs = array("4323254","22222","5123123","23412341234","2222222");<br />$str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";<br /><br />foreach($qqNs as $tmp){<br /> $max = 1;<br /> $qq = $tmp;<br /> while($qq){<br /> for($i=1,$n = floor((strlen($qq)/2));$i <= $n;$i++){<br /> $preTree = substr($qq, 0, $i);<br /> $postTree = substr($qq,$i,$i);<br /> if($preTree == $postTree){<br /> if($i>=$max){<br /> $max = $i;<br /> }<br /> }<br /> }<br /> $qq = substr($qq,1);<br /> }<br /> echo $tmp.": ".substr($str,0,$max)."<br/>";
结果:
4323254: AB<br />22222: AB<br />5123123: ABC<br />23412341234: ABCD<br />2222222: ABC
------解决方案--------------------
不至于吧?全是基础题,不要自己为难自己
一、
$ar = range(1, 54);<br />shuffle($ar);<br />print_r($ar);
二、用正则(既然第一题是基础,那么第二题也不会有过高的要求)
$qq = array('4323254', '5723723');<br />$p = array('/.*(\d\d)\\1.*/', '/.*(\d\d\d)\\1.*/');<br />$r = array('ABAB $0', 'ABCABC $0');<br />$t = preg_replace($p, $r, $qq);<br />print_r($t);Array
(
[0] => ABAB 4323254
[1] => ABCABC 5723723
)
------解决方案--------------------
第二题是什么意思 AB ABC?怎么我看不懂

------解决方案--------------------
第三题flash和php通信,要在flash那边传参数过来才行。
------解决方案--------------------
第二题是指数字中有连续重复循环的现象,就像循环小数那种:4323254和5723723
同理随便几个例子:8742342398,74914891489134
------解决方案--------------------
打个比方,用你的那个正则的形式如果再来一个222222的号码,那就不正确了,不可能说来一个号码加一个规则的
------解决方案--------------------
第三题,可以在游戏开始时,去请求一个php页面,将消息发送至php页面,php页面再去记录玩家玩的信息,如果比如ID,昵称,时间等。也可以直接在flash端使用 socket方式与服务器的服务建立联系。

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools

SublimeText3 Chinese version
Chinese version, very easy to use
