亂序字串(PHP版本)

來源:互聯網
上載者:User
找出一些字串中,的亂序字串,比如 "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教程有興趣的朋友有所協助。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.