学过C++,如果用C++可以做出来,
但现在用PHP,没有接触过不知道PHP的语法,请那位大哥写出来看看。
共三道题:==================================================================================================题目1写一个函数,函数接收的参数是(pStr, pStr_begin, pStr_end),函数输出是一个数组,该数组包含了pStr字符串中所有位于字符串pStr_begin和字符串pStr_end间的字符串。比如, 参数是 '11AgoodB, AbadBqqqAmanB22', 'A', 'B'应该得到一个包含了 'good', 'bad', 'man' 的数组. 
===================================================================================================题目2 写一个函数,函数接收的参数是一个整型奇数n,函数的输出是一个二维数组,用来保存n×n的魔方矩阵。(写出你认为处理速度最快的代码) 
===================================================================================================题目3A.    已知一MySQL 数据库名 DB_test、 账号:root 、密码:123456 . 其中有一个表 TB_test、 表中有ID, Title, Description 3个字段 其中ID是主键,Title和Description 都已建立全文索引。现在要求用php 写一段代码 接收用户输入的内容 在该表里面查询 按照查询结果的近似度输出Title和Description 。B.    用户输入的内容形式有: 1.    a b c (表示标题title字段和内容Description 字段中同时含a b 和 c 字或词)      例如用户输入: 中国 历史 今天 事件 ,要求在查询的结果中 标题和描述中同时含有  中国 历史 今天 事件 四个词2.    a -b c(表示标题title字段和内容Description 字段中同时含a 和 c ,但不包含b)      例如用户输入: 中国 -历史 今天 -事件 ,要求在查询的结果中 标题和描述中同时含有  中国 今天 两个词 同时不含 历史和事件两个词C.    用户输入的字词的数量不定。

解决方案 »

  1.   

    function Q1($pStr, $pStr_begin, $pStr_end) {
    $offset = 0;
    $output = array();
    while (false !== ($p1 = strpos($pStr, $pStr_begin, $offset)) && 
    false !== ($offset = $p2 = strpos($pStr, $pStr_end, $p1)) &&
    $output[] = substr($pStr, ++$p1, $p2 - $p1)) {
    }
    return $output;
    }
      

  2.   

    直接写的没测试,可以作为思路考虑
    //1、
    function c($pStr, $pStr_begin, $pStr_end){
        preg_match_all ("@{$pStr_begin}([^{$pStr_begin}{$pStr_end}]+)$pStr_end@iSU", $pStr, $output);
        var_export($output);
    }
    // 2、参数说明(矩阵宽度, 矩阵填充内容)
    function c($num,$str='*'){
        $str = array_pad($str, $num, $str);
        $str = array_pad($str, $num, $str);
        var_export($str);
    }
    //3、最直接的就是用 Like %% / Not Like %%然后把条件And起来即可
      

  3.   

    <pre>
    <?php
    function q1($pStr, $pStr_begin, $pStr_end)
    {
    preg_match_all('/'.$pStr_begin.'(.*?)'.$pStr_end.'/',$pStr,$out);
    return $out;
    }
    print_r(q1('11AgoodB, AbadBqqqAmanB22', 'A', 'B'));function q2($n)
    {
    for ($i=1;$i<=$n*$n;$i++){
    if ($i==1) {
    $y = 1;
    $x = intval($n/2)+1;
    } else {
    $y = ($oy==1)?$n:$oy-1;
    $x = ($ox==$n)?1:$ox+1;
    if (($oy==1&&$ox==$n)||isset($arr[$y][$x])) {
    $y = $oy+1;
    $x = $ox;
    }
    }
    $oy = $y;
    $ox = $x;
    $arr[$y][$x] = $i;
    }
    $str = '';
    for ($i=1;$i<=$n;$i++) {
    for($j=1;$j<=$n;$j++){
    $str .= "\t".$arr[$i][$j];
    }
    $str .= "\n";
    }
    return $str;
    }
    print_r(q2(3));
    print_r(q2(5));?>
    </pre>
      

  4.   

    google了一下,第二题平面魔法矩阵解法好像千篇一律呀,都是n*n做上界,把1放第一行第二列,然后按一定的排列规律。
     3 1 2
     1 2 3
     2 3 1 
    这个n=3的算不算魔方矩阵?
      

  5.   


    3.
    mysql -uroot -p123456
    select discription,title from TB_test where match(discription,title) against("用户输入数据");
    表类型必须是MyISAM才可以。