php字符串乱序,乱序字符串(PHP版本)

找出一些字符串中,的乱序字符串,比如 "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 )

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();

?>

以上就介绍了乱序字符串(PHP版本),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值