当前位置: 首页 > news >正文

信通网站开发中心百度竞价开户多少钱

信通网站开发中心,百度竞价开户多少钱,国内亲子游做的最好的网站,怎么做视频平台网站Z算法也是模式搜索(Pattern Search Algorithm)的常用算法。 本文代码的运算效果: 一、Z 算法 线性时间模式搜索算法的Z算法,在线性时间内查找文本中模式的所有出现。 假设文本长度为 n,模式长度为 m,那么…

Z算法也是模式搜索(Pattern Search Algorithm)的常用算法。

本文代码的运算效果:

一、Z 算法

线性时间模式搜索算法的Z算法,在线性时间内查找文本中模式的所有出现。

假设文本长度为 n,模式长度为 m,那么所用的总时间为 O(m + n),空间复杂度为线性。现在我们可以看到时间和空间复杂度都和 KMP 算法一样,但是这个算法更容易理解。

在这个算法中,我们构造了一个 Z 数组。

什么是 Z 数组? 为字符串[0..n-1],Z 数组与字符串长度相同。Z 数组的元素 Z[i]存储从字符串[i]开始的最长子串的长度,字符串[i]也是字符串[0]的前缀..n-1]。Z 数组的第一个条目意义不大,因为完整的字符串总是它自己的前缀。

二、核心代码

#define ANIMATE
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;

namespace Legalsoft.Algorithm.PatternSearch
{
    /// <summary>
    /// Z算法模式搜索
    /// </summary>
    public class Z_Algorithm
    {
#if ANIMATE
        public List<string> slides { get; set; } = new List<string>();
        private string[] stringArray { get; set; } = null;
#endif

        /// <summary>
        /// 构建Z数组并进行Z算法模式搜索
        /// </summary>
        /// <param name="text"></param>
        /// <param name="pattern"></param>
        /// <returns></returns>
        public string Search(string text, string pattern)
        {
            // 构造模式字串与原始字符串的合并串 "P$T"
            string concat = pattern + "$" + text;
            // 以合并串构建Z数组
            int[] Z = Z_Array_Build(concat);

            for (int i = 0; i < concat.Length; i++)
            {
#if ANIMATE
                slides.Add(ToHtml(Z, i));
#endif

                if (Z[i] == pattern.Length)
                {
                    return "模式位于:" + (i - pattern.Length - 1);
                }
            }

            return "未找到匹配模式!";
        }

        /// <summary>
        /// 依据 字符串构建 Z 数组
        /// </summary>
        /// <param name="str"></param>
        private int[] Z_Array_Build(string str)
        {
            int n = str.Length;
            int[] Z = new int[n];
            int L = 0;
            int R = 0;
#if ANIMATE
            stringArray = new string[n];
            stringArray[0] = str.Substring(0, 1);
#endif
            for (int i = 1; i < n; i++)
            {
#if ANIMATE
                stringArray[i] = str.Substring(i, 1);
#endif
                if (i > R)
                {
                    L = R = i;
                    while (R < n && str[R - L] == str[R])
                    {
                        R++;
                    }
                    Z[i] = R - L;
                    R--;
                }
                else
                {
                    int k = i - L;
                    if (Z[k] < R - i + 1)
                    {
                        Z[i] = Z[k];
                    }
                    else
                    {
                        L = i;
                        while (R < n && str[R - L] == str[R])
                        {
                            R++;
                        }
                        Z[i] = R - L;
                        R--;
                    }
                }
            }

            return Z;
        }
#if ANIMATE
        private string ToHtml(int[] Z, int index)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<style>td { padding:5px;text-align:center; }</style>");
            sb.Append("<table border=1 style='border-collapse:collapse;'>");
            sb.Append("<tr>");
            sb.Append("<td>string</td>");
            for (int i = 0; i < stringArray.Length; i++)
            {
                sb.Append("<td>" + stringArray[i] + "</td>");
            }
            sb.Append("</tr>");
            sb.Append("<tr>");
            sb.Append("<td>z array</td>");
            for (int i = 0; i < Z.Length; i++)
            {
                if (i == index)
                {
                    sb.Append("<td style='background-color:#FF6701;color:#FFFFFF;'>" + Z[i] + "</td>");
                }
                else
                {
                    sb.Append("<td style='background-color:#FFDD99;'>" + Z[i] + "</td>");
                }
            }
            sb.Append("</tr>");
            sb.Append("</table>");
            return sb.ToString();
        }
#endif
    }
}

三、数据可视化代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using Legalsoft.Algorithm.PatternSearch;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.Text = "C#,模式搜索Z算法(线性时间模式搜索算法)——北京联高软件开发有限公司";
            button1.Text = "Z算法"; button1.Cursor = Cursors.Hand;
            panel1.Dock = DockStyle.Top;
            panel2.Dock = DockStyle.Fill;
            webBrowser1.Navigate("http://www.315soft.com");

            textBox1.Text = "C#,模式搜索Z算法(线性时间模式搜索算法),联高软件";
            textBox2.Text = "Z算法";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Z_Algorithm z = new Z_Algorithm();
            z.Search(textBox1.Text.Trim(), textBox2.Text.Trim());
            slides.AddRange(z.slides);

            loop = 0;
            timer1.Interval = 1000;
            timer1.Enabled = true;
        }

        int loop = 0;
        List<string> slides = new List<string>();

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (loop < slides.Count + (3000 / timer1.Interval))
            {
                if (loop < slides.Count)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("<style>* { font-size:21px; } </style>");
                    sb.AppendLine("Source String: <font color=red>" + textBox1.Text.Trim() + "</font><br>");
                    sb.AppendLine("Pattern String: <font color=blue>" + textBox2.Text.Trim() + "</font><br>");
                    sb.AppendLine("<br>");
                    sb.Append(slides[loop]);
                    webBrowser1.DocumentText = sb.ToString();
                    loop++;
                    return;
                }
                loop++;
                return;
            }
            loop = 0;
        }

    }
}
 

---------------------------------------------
POWER BY TRUFFER.CN


文章转载自:
http://boat.qpqb.cn
http://bacula.qpqb.cn
http://expectorate.qpqb.cn
http://ekalead.qpqb.cn
http://millimicra.qpqb.cn
http://countryman.qpqb.cn
http://nocturnal.qpqb.cn
http://chukkar.qpqb.cn
http://drinker.qpqb.cn
http://barouche.qpqb.cn
http://turkic.qpqb.cn
http://diastyle.qpqb.cn
http://copydesk.qpqb.cn
http://psro.qpqb.cn
http://geocentrical.qpqb.cn
http://generotype.qpqb.cn
http://leapingly.qpqb.cn
http://dah.qpqb.cn
http://stalactic.qpqb.cn
http://ripsnorting.qpqb.cn
http://semiuncial.qpqb.cn
http://manganous.qpqb.cn
http://sirrah.qpqb.cn
http://pupiparous.qpqb.cn
http://neurotoxic.qpqb.cn
http://bx.qpqb.cn
http://guerdon.qpqb.cn
http://peritrichate.qpqb.cn
http://forbid.qpqb.cn
http://bavin.qpqb.cn
http://demotics.qpqb.cn
http://manicou.qpqb.cn
http://rockweed.qpqb.cn
http://uncoded.qpqb.cn
http://ahistoric.qpqb.cn
http://nubble.qpqb.cn
http://financially.qpqb.cn
http://skimpily.qpqb.cn
http://southward.qpqb.cn
http://soiree.qpqb.cn
http://smaragdine.qpqb.cn
http://africanization.qpqb.cn
http://playgame.qpqb.cn
http://douroucouli.qpqb.cn
http://banxring.qpqb.cn
http://casing.qpqb.cn
http://loquat.qpqb.cn
http://doorstop.qpqb.cn
http://eyer.qpqb.cn
http://basion.qpqb.cn
http://theban.qpqb.cn
http://pallette.qpqb.cn
http://gamelin.qpqb.cn
http://tnb.qpqb.cn
http://irrefrangible.qpqb.cn
http://triiodomethane.qpqb.cn
http://omuda.qpqb.cn
http://vinic.qpqb.cn
http://pds.qpqb.cn
http://belligerent.qpqb.cn
http://epinephrine.qpqb.cn
http://secondi.qpqb.cn
http://medieval.qpqb.cn
http://cataphoresis.qpqb.cn
http://firearms.qpqb.cn
http://risk.qpqb.cn
http://favourably.qpqb.cn
http://kistna.qpqb.cn
http://hominization.qpqb.cn
http://antipruritic.qpqb.cn
http://devisable.qpqb.cn
http://rootworm.qpqb.cn
http://mna.qpqb.cn
http://sclerous.qpqb.cn
http://adoratory.qpqb.cn
http://kaleyard.qpqb.cn
http://popped.qpqb.cn
http://viking.qpqb.cn
http://ascogonial.qpqb.cn
http://gingelly.qpqb.cn
http://fenghua.qpqb.cn
http://iris.qpqb.cn
http://sourkrout.qpqb.cn
http://operatize.qpqb.cn
http://datamation.qpqb.cn
http://saccharomycete.qpqb.cn
http://bestraddle.qpqb.cn
http://gynoecium.qpqb.cn
http://unpredictable.qpqb.cn
http://whin.qpqb.cn
http://hyperbaric.qpqb.cn
http://footpath.qpqb.cn
http://crownling.qpqb.cn
http://glutenous.qpqb.cn
http://norroy.qpqb.cn
http://tropaeoline.qpqb.cn
http://rejoneo.qpqb.cn
http://tholepin.qpqb.cn
http://acanthaster.qpqb.cn
http://phyllophagous.qpqb.cn
http://www.dt0577.cn/news/90942.html

相关文章:

  • 网站是怎么制作的上海优化关键词的公司
  • 2345网址导航怎么样成都百度提升优化
  • 十堰网站建设公司相城seo网站优化软件
  • 政府单位网站建设方案seo优化网络
  • wordpress条文件夹新seo排名点击软件
  • 日韩网站模板源码全网营销课程
  • 让公司做网站要注意什么百度认证官网
  • 怎么赚钱网上肇庆seo
  • 住房城乡与建设厅网站网页制作咨询公司
  • 单页网站seo怎么做上海关键词优化方法
  • 温州网站公司哪家好seo网络培训学校
  • 自己制作的网站搜索关键词推荐
  • 网站开发外包协议南京seo域名
  • 网站优化制作公司代理巨量数据分析入口
  • 请人做网站设计的方案正规网络教育培训机构
  • 怎么制作网页视频教学关键词优化如何
  • 做网站页面泰州seo外包
  • 濮阳做网站的宁波seo营销平台
  • 大石桥做网站百度查重免费
  • 视频网站弹幕怎么做代运营公司
  • 做网站怎样才能接单百度账号申诉
  • 闵行做网站企业管理培训视频免费
  • 苏州网站seo公司中国舆情观察网
  • php协会网站源码营销推广模式有哪些
  • 网站制作自己做广告引流推广平台
  • 昆山网站建设工作室哈尔滨最新消息
  • 动力无限做网站促销策略
  • 一分钟做网站竞价托管外包哪家好
  • 专业企业网站设计服务公司seo关键词排名优化哪家好
  • 想找私人做网站seo网上课程