Little Red Book Written 1

package compressed string; 
Import java.util.Scanner; 
/ * * 
 * @author T470s 
 * 
 after * the input character string, write a string compression procedure will be repeated in consecutive letter string is compressed, and the compressed output String. 
        For example: 
        AAC compressed 1AC 
        xxxxyyyyyyzbbb compressed 3x5yz2b 
 * 
 * / 
public  class MainTest {
     public  static  void main (String [] args) { 
        String [] SS = new new Scanner (the System. In ) .nextLine () Split (. "" ) ;
         int length = ss.length; 
        String S = SS [ 0 ]; // different characters stored
        int COUNT = 0 ; // number of storage 
        the StringBuilder SB = new new the StringBuilder (); // target string storage 
        for ( int I = . 1 ; I <length; I ++ ) {
             IF (s.equals (SS [I])) { 
               COUNT ++ ; 
            } the else {
                 IF (COUNT =! 0 ) { 
                    sb.append (COUNT); 
                } 

                sb.append (SS [I - . 1 ]); 
                S =  SS [I];
                COUNT = 0 ; 
            } 
        } 
        sb.append (COUNT); // the last addition to doing sb the 
        sb.append (SS [Length- . 1 ]); 
        . the System OUT .println (sb.toString ()); 
    } 
}

 

Guess you like

Origin www.cnblogs.com/JimShi/p/11444974.html