乱序字符串(PHP版本)
来源:互联网 发布:4.5铅弹淘宝店 编辑:程序博客网 时间:2024/04/28 08:35
找出一些字符串中,的乱序字符串,比如 "abc","cba"是一组乱序字符串
样例
输入:(hello,lloeh,helll,olelh,code,abc,cba,dec,asd,bca,);
输出:
array ( [0] => hello [1] => lloeh [2] => olelh [3] => abc [4] => cba [5] => bca )
<?phpclass Map { public $b; public function __construct(){$this->b = array();$s = 'a';for ($i =0;$i < 26; $i++) { $this->b[$s] = 0;$s++;}}}class Jumble { private $a; private $m; private $key; private $result; public function __construct(){ $this->a = array(hello,lloeh,helll,olelh,code,abc,cba,dec,asd,bca,); $this->m = count($this->a); $this->key = array(); for ($k =0; $k < $this->m; $k++) { $this->key[$k]=0; } $this->result = array(); } public function slove() { for ($i = 0; $i < $this->m; $i++) { for ($q = $i + 1; $q < $this->m; $q++) { $s1 = $this->a[$i]; $s2 = $this->a[$q]; $len1 = strlen($s1); $len2 = strlen($s2); if ($len1 == $len2) { $bool = true; $t1 = new Map(); $t2 = new Map(); for ($j = 0; $j < $len1; $j++) { $w1 = $s1[$j]; $w2 = $s2[$j]; $t1->b[$w1]++; $t2->b[$w2]++; } $ss = 'a'; for ($p = 0; $p < 26; $p++) { if ($t1->b[$ss] != $t2->b[$ss]) { $bool = false; } $ss++; } if ($bool == true) { if ($this->key[$i] == 0) { array_push( $this->result, $s1); $this->key[$i] = 1; } if ($this->key[$q] == 0) { array_push( $this->result, $s2); $this->key[$q] = 1; } } } } } } public function prints() { print_r( $this->result); }} $r = new Jumble(); $r->slove(); $r->prints();?>
0 0
- 乱序字符串(PHP版本)
- LintCode-乱序字符串
- 乱序字符串
- 题目:乱序字符串
- 乱序字符串
- LintCode 乱序字符串
- 乱序字符串
- (171)乱序字符串
- 乱序字符串_LintCode
- LintCode:乱序字符串
- 乱序字符串
- 乱序字符串算法
- 乱序字符串
- lintcode,乱序字符串
- 乱序字符串
- lintcode--乱序字符串
- 乱序字符串-LintCode
- 乱序字符串
- Android中AsyncTask的简单用法
- HDU 1572 下沙小面的(2) 【DFS】
- hdoj 2501 Tiling_easy version
- Gephi作网络图
- gps导航卫星星历及历书参数意义
- 乱序字符串(PHP版本)
- Clone
- web.xml加载顺序与web.xml常用节点解析
- iOS7滑动返回总结
- linux多线程中信号的使用(2)
- 自然数倒数平方求和
- 测试case自动化代码框架
- poj 3253 哈夫曼树
- HDU 1181 变形课 【DFS】