欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

乱序字符串(PHP版本)

程序员文章站 2022-04-27 23:06:08
...
找出一些字符串中,的乱序字符串,比如 "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 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 m; $k++) {
            $this->key[$k]=0;
        }
        $this->result = array();
    }
    public function slove() {
        for ($i = 0; $i m; $i++) {
            for ($q = $i + 1; $q 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 b[$w1]++;
                        $t2->b[$w2]++;
                    }
                    $ss = 'a';
                    for ($p = 0; $p 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教程有兴趣的朋友有所帮助。