package com.lovecoding.day16;

import org.junit.Test;

import java.util.Arrays;

public class Test01 {

    public static void main(String[] args) {
        String str=findMaxSubString("abcwerthelloyuiodef","cvhellobnm");
        System.out.println(str);
    }

    //提示：将短的那个串进行长度依次递减的子串与较长的串比较。
    public static String findMaxSubString(String str1,String str2){
        String result="";

        String mixStr = str1.length()<str2.length()?str1:str2;
        String maxStr = str1.length()>str2.length()?str1:str2;

        String rr = "";

        //外循环控制从左到右的下标，内循环控制从右到左的下标
        for (int i = 0; i < mixStr.length() ; i++) {
            for (int j = 0; j < mixStr.length()-i; j++) {


                String substring = mixStr.substring(i, mixStr.length() - j);
//                System.out.println(i+"---"+(mixStr.length()-j));
//                System.out.println(substring);
                if (maxStr.contains(substring)){
                    if (substring.length()>rr.length()){
                        rr = substring;
                    }
                }
            }
        }
        return rr;
    }

    @Test
    public void test033(){
        String str = "1.hello2.world3.java4.string";
        String s = str.replaceAll("(^\\d.)|(\\d.$)", "");

        System.out.println(s);

        String[] split = s.split("\\d.");
        System.out.println(Arrays.toString(split));
    }

    @Test
    public void test022(){
        String str = "aaaaaaaaaaaabbbbbbyolhljlhlxxmnbwyteuhfhjloiqqbhrg";

        int[] a1 = new int[26];

        char[] chars = str.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            a1[chars[i]-97]++;
        }

        int max = a1[0];

        for (int i = 0; i < a1.length; i++) {
            if (a1[i]>max){
                max=a1[i];
            }
        }

        for (int i = 0; i < a1.length; i++) {
            if ( a1[i] ==max ){
                System.out.println( (char) (i+97));
                System.out.println(a1[i]);
            }
        }


    }
    @Test
    public void test011(){
        String[] arr = {"helloworld","java","xiaochai","lovecoding","lin","yan","I love you"};

        System.out.println("原字符串：");
        System.out.println( Arrays.toString(arr));

        int count = arr.length;
        for (int i = 0; i < count; i++) {
            if (arr[i].length()>5){
                System.arraycopy(arr,i+1,arr,i,count-i-1);
                count--;
                i--;
            }
        }
        String[] strings = Arrays.copyOf(arr, count);
        System.out.println(Arrays.toString(strings));


    }

    @Test
    public void m1(){
        String qq= "11111";
        boolean matches = qq.matches("[1-9][0-9]{4,11}+");
        System.out.println(matches);
    }

    @Test
    public void call(){
        String str ="abcdefgho";
        String s = reverse1(str, 2, 6);
        System.out.println(s);
    }


    public String reverse1(String str,int start,int end){

        char[] array = str.toCharArray();

        for(int i = start;i < end;i++){
            char temp =array[i];
            array[i]=array[end-i-1];
            array[end-i-1]=temp;
        }
        String s = new String(array);
        return s;
    }
    @Test
    public void test02(){
        String str ="    he   llo   ";

        String s = str.replaceAll("^\\s*", "");
        String s1 = s.replaceAll("\\s*$", "");
//        while (str.startsWith(" ")){
//            str = str.replaceFirst(" ","");
//        }
        System.out.println(s1);


    }

    @Test
    public void test01(){
        String str = "abcd12345cd125se123456789ss";

        String s = str.replaceAll("(^[a-zA-z]+)|([a-zA-z]+$)", "");

        System.out.println(s);

        String[] split = s.split("[a-zA-z]+");
        System.out.println(Arrays.toString(split));

    }
}
