1
CoX 2013-01-17 01:10:56 +08:00 1
嵌套调用呗,跟遍历文件夹下的文件一个思路吧
|
2
alexrezit 2013-01-17 01:16:47 +08:00 1
Recursion...
|
4
txx 2013-01-17 02:07:24 +08:00 via iPhone 1
dfs bfs 都可以
我更喜欢bfs一些 |
5
endyul 2013-01-17 12:27:37 +08:00 1
用“种”函数构造个树再先根遍历一下
|
9
Sunyanzi 2013-01-17 17:02:55 +08:00 1
<?php
// Sunyanzi @V2EX /* make a flowerpot ... */ $flowerpot = []; /* we have 7 seeds at first ... */ seeding_time( $flowerpot, 0, 7 ); /* simple output ... */ echo( implode( ' ', $flowerpot ) ); /* main function ... using Recursion which is @alexrezit's favourite ... */ function seeding_time( &$ret, $prefix, $number ) { /* the seeds we planted can sprouted ... */ static $seeds = [ 3 => 5, 7 => 2, 31 => 3 ]; /* seeding in progress ... */ for ( $i = 1; $i <= $number; ++ $i ) { /* most easy way to get seed number ... */ $s = intval( $prefix . $i ); /* push into result ... */ $ret[] = $s; /* we have magic on this seed ..? */ if ( isset( $seeds[$s] ) ) seeding_time( $ret, $s, $seeds[$s] ); } /* we have done ... */ return; } // -------------------------------------------------- // DEMO OUTPUT // -------------------------------------------------- // 1 2 3 31 311 312 313 32 33 34 35 4 5 6 7 71 72 // -------------------------------------------------- |
10
Sunyanzi 2013-01-17 17:06:04 +08:00
花了大概五分钟顺手一写效率没优化 ...
说来 ... 看到自己的代码变成这样黑乎乎的一陀还真不是个好受的事情啊 ... |
13
nichan OP 非常感谢各位。。。最后还是用了递归解决问题。。。
果然之前学到的还是都还给老师了吧。。 |