Main Menu  | 
         
        
            | 
	
            
 | 
         
        
            | 
         
       
        
           
            Forums  | 
           
           
            |  
             | 
           
           
              | 
           
         
        
        
           
            Programming 
                Contest  | 
           
           
            |   | 
           
           
              | 
           
         
        
        
           
            Documentation 
                | 
           
           
            |   | 
           
           
              | 
           
         
        
        
           
            Partner 
                Sites   | 
           
           
             
 
 | 
           
           
              | 
           
         
        
        
           
            Sponsors  | 
           
           
            | 
				 | 
           
           
              | 
           
         
       
       
     | 
    
        
          
 
Code of zander 
<?php
  /*  *  Written by: Alexander A. Magtipon  *              zander@digi.com.ph  *              Copyright (c) 2003  *  */
  class zJumbledWords {     var $char_pool = 'abcdefghijklmnopqrstuvwxyz';     var $input_array = array();     var $output_array = array();     var $char_count = 0;          var $_input_loaded = false;     var $_blank_chars = 2;     var $_cur_blank_cpool = '';     var $_cur_input_cpool = '';     var $_cur_output_str = '';     var $_cur_search_array = array();          var $_cur_blank_buf = '';     var $_cur_output_buf = '';          //--------------------------------------------------------------------------     function loadInput( $f_path='' )     {         clearstatcache();         if( !is_file($f_path) )         {             echo "No input file...(lists.txt expected) !!!";             return $this->_input_loaded;         }         $f_str = implode( '',@file($f_path) );         $f_str = str_replace( array("\r","\n"),'',$f_str );         $this->input_array = preg_split( '/\./',trim($f_str),-1,PREG_SPLIT_NO_EMPTY );         $this->_input_loaded = true;         return 0;     }     //--------------------------------------------------------------------------     function parseInput()     {         if( !$this->_input_loaded )             return $this->_input_loaded;         foreach( $this->input_array as $input )         {             $this->_resetBuffers();             $this->_loadInputItem( $input );             $this->_parseInputItem();         }     }     //--------------------------------------------------------------------------     function printOutput()     {         if( !$this->_input_loaded )             return $this->_input_loaded;         foreach( $this->output_array as $str )         {             echo "$str <br>";         }         echo "$this->char_count";     }     //--------------------------------------------------------------------------     function _loadInputItem( $input )     {         $a_tmp = explode( ',',$input );         $this->_cur_search_array = explode( ' ',trim($a_tmp[0]) );         $this->_cur_input_cpool = trim( $a_tmp[1] );     }     //--------------------------------------------------------------------------     function _parseInputItem()     {         $this->_arraySortByLength( $this->_cur_search_array,'DESC' );         foreach( $this->_cur_search_array as $str )         {             $tmpstr = '';             $char_count = 0;             for( $i=0;$i<strlen($str);$i++ )             {                 $blank = false;                 $char = $this->_fetchCharFromPool( $str{$i} );                 if( !$char )                 {                     $char = $this->_fetchBlankChar( $str{$i} );                     $blank = true;                 }                 if( !$char )                 {                     $this->_resetItemBuf();                     $tmpstr = '';                     $char_count = 0;                     break;                 }else                 {                     $tmpstr .= ( $blank ) ? '<font color=red>'.$char.'</font>' : $char ;                     $char_count++;                 }             }             if( $tmpstr )             {                 $this->char_count += $char_count;                 $this->_cur_output_str .= $tmpstr.' ';             }         }         $this->output_array[] = $this->_cur_output_str;     }     //--------------------------------------------------------------------------     function _fetchCharFromPool( $char )     {         $retchar = $this->_stringPop( $this->_cur_input_cpool,$char );         $this->_cur_output_buf .= $retchar;         return $retchar;     }     //--------------------------------------------------------------------------     function _fetchBlankChar( $char )     {         $blank = '';         if( $this->_blank_chars>0 )         {             $blank = $this->_stringPop( $this->_cur_blank_cpool,$char );             $this->_cur_blank_buf .= $blank;             $this->_blank_chars--;         }         return $blank;     }     //--------------------------------------------------------------------------     function _stringPop( &$str,$char )     {         $retchar = '';         $pos = strpos( $str,$char );         if( $pos!==false )         {             $retchar = substr( $str,$pos,strlen($char) );             $str = substr_replace( $str,'',$pos,strlen($char) );         }         return $retchar;     }     //--------------------------------------------------------------------------     function _arraySortByLength( &$array,$order='ASC' )     {         usort( $array,'strnatcasecmp' );         if( $order=='DESC' )             $array = array_reverse( $array );     }     //--------------------------------------------------------------------------     function _resetItemBuf()     {         $this->_cur_blank_cpool .= $this->_cur_blank_buf;         $this->_cur_input_cpool .= $this->_cur_output_buf;         $this->_cur_blank_buf = '';         $this->_cur_output_buf = '';     }     //--------------------------------------------------------------------------     function _resetBuffers()     {         $this->_blank_chars = 2;         $this->_cur_blank_cpool = $this->char_pool;         $this->_cur_input_cpool = '';         $this->_cur_output_str = '';         $this->_cur_search_array = array();
          $this->_cur_blank_buf = '';         $this->_cur_output_buf = '';     }     //-------------------------------------------------------------------------- }
 
  $jwobj = new zJumbledWords(); $jwobj->loadInput( 'lists.txt' ); $jwobj->parseInput(); $jwobj->printOutput();
  ?> 
Back to results
  | 
 
 
 | 
   
 
 |