zoukankan      html  css  js  c++  java
  • 测试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

  • 相关阅读:
    flask笔记(引用)
    三元表达式(列表解析+if)
    生成器
    闭包、装饰器、高阶函数
    列表的解压和取值
    模块
    时间操作
    day16 css, dom
    day 15 html(2) css,javascript,dom
    day 14 html
  • 原文地址:https://www.cnblogs.com/lpbk/p/11346835.html
Copyright © 2011-2022 走看看