• 字符串匹配


    判断str2中是否存在一个序列的集合 ix......im,使得str2(ix...im)=str1, ix不要求连续,且间隔的字符不能是str1中字符

    str2="acsbassbba"

    str1="abab"

    不匹配

    str2="acsbassba"

    str1="abab"

    匹配

    对str1中出现的字符做一次hash记录.

    找出所有str2中str1[0]字符的下标,for 循环此下标,如果出现不匹配,判断是不是str1的字符

    public class Main
    {
    
        public static void main(String[] args)
        {
            String str1 = "abab";
            String str2 = "acsbassbba";
            int a[] = new int[26];
            int b[] = new int[str2.length()];
            int bl = 0;
            for (int i = 0; i < str1.length(); i++)
                a[str1.charAt(0) - 'a'] = 1;
            for (int i = 0; i < str2.length(); i++)
                if (str2.charAt(i) == str1.charAt(0))
                {
                    b[bl++] = i;
                }
            int si = 1;
            for (int i️ = b[0] + 1; i️ < bl; i️++)
            {
                si = 1;
                for (int j = b[0] + 1; j < str2.length() && si != str1.length(); ++j)
                {
                    if (str1.charAt(si) == str2.charAt(j))
                    {
                        ++si;
                    }
                    else
                    {
                        // 判断是否是str1中的字符
                        if (a[str2.charAt(j)-'a'] == 1)
                        {
                            // 错误的匹配
                            break;
                        }
                        // 不是j++
                    }
                }
            }
            if (bl != 0 && si == str1.length()) System.out.println("ok");
            else
                System.out.println("false");
        }
    
    }
  • 相关阅读:
    django自带登录认证与登录自动跳转
    11月份草稿2
    使用JavaScript实现字符串格式化
    requests与BeautifulSoup
    python+minicap(二)
    python+minicap的使用
    python+opencv图像处理(一)
    haproxy实现mysql从库负载均衡
    mysql 5.7 64位 解压版安装
    Redis基础教程
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/9934383.html
Copyright © 2020-2023  润新知