• 测试3---将字符串压缩算法


     1 package com.review;
     2 
     3 import java.util.Scanner;
     4 
     5 /**
     6  * @program: com.review
     7  * @description:
     8  * @author: Mr.Lin
     9  * @create: 2019年8月13日
    10  **/
    11 public class Compress03 {
    12     static Scanner sc= new Scanner(System.in);
    13     public static void main(String[] args) {
    14         System.out.println("输入:");
    15         String cluster = sc.next();
    16         
    17         String s1 = cluster + " ";
    18         String s3 = "";
    19         
    20         int index;
    21         do {
    22             index = 0;
    23             for(int i=0;i<s1.length();i++) {
    24                 if(s1.charAt(i)!=s1.charAt(i+1)) {
    25                     index = i+1;
    26                     break;
    27                 }
    28             }
    29             String s2 = s1.substring(0, index);
    30             s3 += s2.charAt(0) + "" + ((s2.length()-1) == 0 ? "" : s2.length());
    31             s1 = s1.substring(index, s1.length());
    32         }while(s1.length()>1);
    33         System.out.println("输出:
    "+s3);
    34     } 
    35     
    36 }
    View Code

  • 相关阅读:
    Http中GET和POST两种请求的区别
    JSON学习笔记
    分页
    python 函数,闭包
    LVS负载均衡中arp_ignore和arp_annonuce参数配置的含义
    return ;
    openssl 在php里
    重装drupal
    protected的意义
    和 和 notepad++
  • 原文地址:https://www.cnblogs.com/lpbk/p/11346835.html
Copyright © 2020-2023  润新知