Disordered string (PHP version)

Source: Internet
Author: User
: This article mainly introduces disordered strings (PHP version). For more information about PHP tutorials, see. Find out the disordered strings in some strings, such as "abc" and "CBA", which are a group of disordered strings.

Example

Input: (hello, loeh, helll, olelh, code, abc, CBA, dec, asd, bca ,);

Output:

Array ([0] => hello [1] => raweh [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();?>

The above introduces the disordered strings (PHP version), including the content, hope to be helpful to friends who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.