- 浏览: 65076 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
real_yqdt:
...
关于Java thread的Interrupt, isInterrupt, interrupted -
二当家的:
while需要写在try里面
关于Java thread的Interrupt, isInterrupt, interrupted -
sampras87:
mojunbin 写道
public void run() { ...
关于Java thread的Interrupt, isInterrupt, interrupted -
boaixiaohai:
mojunbin 写道
public void run() { ...
关于Java thread的Interrupt, isInterrupt, interrupted -
sp42:
学习了,谢谢!
巧妙的位运算及模运算
最近在研究一些字符串的算法,准备做一个diff的小工具
首先第一步是解决求两个字符串里面最大公共字串的问题,趁着周末看了一些资料
从T.T.tick那里拿到的一些资料:
http://www.rainsts.net/article.asp?id=767
http://www.cnblogs.com/TtTiCk/archive/2007/08/04/842819.html
自己实现以上资料算法(未经过完整的单元测试,但在几个试验中可以获取正确的的最大公共子串了):
另外,还在某个开源组织拿到的一些diff算法的代码:
会继续再试,有新进展会贴上来 ^_^
首先第一步是解决求两个字符串里面最大公共字串的问题,趁着周末看了一些资料
从T.T.tick那里拿到的一些资料:
http://www.rainsts.net/article.asp?id=767
http://www.cnblogs.com/TtTiCk/archive/2007/08/04/842819.html
自己实现以上资料算法(未经过完整的单元测试,但在几个试验中可以获取正确的的最大公共子串了):
package test; import java.lang.String; public class LCSTest { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String str1 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + "dddddddddddddddddddddddddddddddddd" + "ddddddddddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddddddddddddd" + "ddddddddddddddddddddddddddddddddddddddddddd" + "ddddddddddddddddddddddddddddddddddddddddddddd" + "ddddddddddddddddddddddddddddddddddddddddddddadfeasdf" + "amydonTangoisagoodpersonoBon"; String str2 = "jayamTangoisfffffffffffffffffffffeeeeeeeeeeeeee" + "adfffffffffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffffffff" + "ddddddddddddddddddddddddddddddddddddddddddddddd" + "agoodipersondoo"; System.out.println(LCS(str1,str2)); } public static String LCS(String str1, String str2){ int[][] LCSArray = new int[str1.length()][str2.length()]; int maxValue = 0; int xMax = 0; int yMax = 0; for (int x = 0; x< str1.length(); x++){ for (int y=0; y<str2.length(); y++){ if (str1.charAt(x)==str2.charAt(y)){ if (x>0 && y>0){ LCSArray[x][y]=LCSArray[x-1][y-1] +1; if (LCSArray[x][y]> maxValue){ maxValue = LCSArray[x][y]; xMax = x; yMax = y; } }else{ LCSArray[x][y]=1; } }else { LCSArray[x][y]=0; } System.out.print(LCSArray[x][y]); if (y == str2.length()-1){ System.out.println(); } } } if (maxValue != 0){ System.out.println("xMax:" + xMax); System.out.println("maxValue:" + maxValue); return str1.substring(xMax-maxValue+1, xMax+1); } else { return null; } } }
另外,还在某个开源组织拿到的一些diff算法的代码:
namespace my.utils { using System; using System.Collections; using System.Text; using System.Text.RegularExpressions; /// <summary> /// This Class implements the Difference Algorithm published in /// "An O(ND) Difference Algorithm and its Variations" by Eugene Myers /// Algorithmica Vol. 1 No. 2, 1986, p 251. /// /// There are many C, Java, Lisp implementations public available but they all seem to come /// from the same source (diffutils) that is under the (unfree) GNU public License /// and cannot be reused as a sourcecode for a commercial application. /// There are very old C implementations that use other (worse) algorithms. /// Microsoft also published sourcecode of a diff-tool (windiff) that uses some tree data. /// Also, a direct transfer from a C source to C# is not easy because there is a lot of pointer /// arithmetic in the typical C solutions and i need a managed solution. /// These are the reasons why I implemented the original published algorithm from the scratch and /// make it avaliable without the GNU license limitations. /// I do not need a high performance diff tool because it is used only sometimes. /// I will do some performace tweaking when needed. /// /// The algorithm itself is comparing 2 arrays of numbers so when comparing 2 text documents /// each line is converted into a (hash) number. See DiffText(). /// /// Some chages to the original algorithm: /// The original algorithm was described using a recursive approach and comparing zero indexed arrays. /// Extracting sub-arrays and rejoining them is very performance and memory intensive so the same /// (readonly) data arrays are passed arround together with their lower and upper bounds. /// This circumstance makes the LCS and SMS functions more complicate. /// I added some code to the LCS function to get a fast response on sub-arrays that are identical, /// completely deleted or inserted. /// /// The result from a comparisation is stored in 2 arrays that flag for modified (deleted or inserted) /// lines in the 2 data arrays. These bits are then analysed to produce a array of Item objects. /// /// Further possible optimizations: /// (first rule: don't do it; second: don't do it yet) /// The arrays DataA and DataB are passed as parameters, but are never changed after the creation /// so they can be members of the class to avoid the paramter overhead. /// In SMS is a lot of boundary arithmetic in the for-D and for-k loops that can be done by increment /// and decrement of local variables. /// The DownVector and UpVector arrays are alywas created and destroyed each time the SMS gets called. /// It is possible to reuse tehm when transfering them to members of the class. /// See TODO: hints. /// /// diff.cs: A port of the algorythm to C# /// Created by Matthias Hertel, see http://www.mathertel.de /// This work is licensed under a Creative Commons Attribution 2.0 Germany License. /// see http://creativecommons.org/licenses/by/2.0/de/ /// /// Changes: /// 2002.09.20 There was a "hang" in some situations. /// Now I undestand a little bit more of the SMS algorithm. /// There have been overlapping boxes; that where analyzed partial differently. /// One return-point is enough. /// A assertion was added in CreateDiffs when in debug-mode, that counts the number of equal (no modified) lines in both arrays. /// They must be identical. /// /// 2003.02.07 Out of bounds error in the Up/Down vector arrays in some situations. /// The two vetors are now accessed using different offsets that are adjusted using the start k-Line. /// A test case is added. /// /// 2006.03.05 Some documentation and a direct Diff entry point. /// /// 2006.03.08 Refactored the API to static methods on the Diff class to make usage simpler. /// 2006.03.10 using the standard Debug class for self-test now. /// compile with: csc /target:exe /out:diffTest.exe /d:DEBUG /d:TRACE /d:SELFTEST Diff.cs /// </summary> public class Diff { /// <summary>details of one difference.</summary> public struct Item { /// <summary>Start Line number in Data A.</summary> public int StartA; /// <summary>Start Line number in Data B.</summary> public int StartB; /// <summary>Number of changes in Data A.</summary> public int deletedA; /// <summary>Number of changes in Data A.</summary> public int insertedB; } // Item /// <summary> /// Shortest Middle Snake Return Data /// </summary> private struct SMSRD { internal int x, y; // internal int u, v; // 2002.09.20: no need for 2 points } #region self-Test #if (SELFTEST) /// <summary> /// start a self- / box-test for some diff cases and report to the debug output. /// </summary> /// <param name="args">not used</param> /// <returns>always 0</returns> public static int Main(string[] args) { StringBuilder ret = new StringBuilder(); string a, b; System.Diagnostics.ConsoleTraceListener ctl = new System.Diagnostics.ConsoleTraceListener(false); System.Diagnostics.Debug.Listeners.Add(ctl); System.Console.WriteLine("Diff Self Test..."); // test all changes a = "a,b,c,d,e,f,g,h,i,j,k,l".Replace(',', '\n'); b = "0,1,2,3,4,5,6,7,8,9".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "12.10.0.0*", "all-changes test failed."); System.Diagnostics.Debug.WriteLine("all-changes test passed."); // test all same a = "a,b,c,d,e,f,g,h,i,j,k,l".Replace(',', '\n'); b = a; System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "", "all-same test failed."); System.Diagnostics.Debug.WriteLine("all-same test passed."); // test snake a = "a,b,c,d,e,f".Replace(',', '\n'); b = "b,c,d,e,f,x".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "1.0.0.0*0.1.6.5*", "snake test failed."); System.Diagnostics.Debug.WriteLine("snake test passed."); // 2002.09.20 - repro a = "c1,a,c2,b,c,d,e,g,h,i,j,c3,k,l".Replace(',', '\n'); b = "C1,a,C2,b,c,d,e,I1,e,g,h,i,j,C3,k,I2,l".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "1.1.0.0*1.1.2.2*0.2.7.7*1.1.11.13*0.1.13.15*", "repro20020920 test failed."); System.Diagnostics.Debug.WriteLine("repro20020920 test passed."); // 2003.02.07 - repro a = "F".Replace(',', '\n'); b = "0,F,1,2,3,4,5,6,7".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "0.1.0.0*0.7.1.2*", "repro20030207 test failed."); System.Diagnostics.Debug.WriteLine("repro20030207 test passed."); // Muegel - repro a = "HELLO\nWORLD"; b = "\n\nhello\n\n\n\nworld\n"; System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "2.8.0.0*", "repro20030409 test failed."); System.Diagnostics.Debug.WriteLine("repro20030409 test passed."); // test some differences a = "a,b,-,c,d,e,f,f".Replace(',', '\n'); b = "a,b,x,c,e,f".Replace(',', '\n'); System.Diagnostics.Debug.Assert(TestHelper(Diff.DiffText(a, b, false, false, false)) == "1.1.2.2*1.0.4.4*1.0.6.5*", "some-changes test failed."); System.Diagnostics.Debug.WriteLine("some-changes test passed."); System.Diagnostics.Debug.WriteLine("End."); System.Diagnostics.Debug.Flush(); return (0); } public static string TestHelper(Item []f) { StringBuilder ret = new StringBuilder(); for (int n = 0; n < f.Length; n++) { ret.Append(f[n].deletedA.ToString() + "." + f[n].insertedB.ToString() + "." + f[n].StartA.ToString() + "." + f[n].StartB.ToString() + "*"); } // Debug.Write(5, "TestHelper", ret.ToString()); return (ret.ToString()); } #endif #endregion /// <summary> /// Find the difference in 2 texts, comparing by textlines. /// </summary> /// <param name="TextA">A-version of the text (usualy the old one)</param> /// <param name="TextB">B-version of the text (usualy the new one)</param> /// <returns>Returns a array of Items that describe the differences.</returns> public Item [] DiffText(string TextA, string TextB) { return(DiffText(TextA, TextB, false, false, false)); } // DiffText /// <summary> /// Find the difference in 2 text documents, comparing by textlines. /// The algorithm itself is comparing 2 arrays of numbers so when comparing 2 text documents /// each line is converted into a (hash) number. This hash-value is computed by storing all /// textlines into a common hashtable so i can find dublicates in there, and generating a /// new number each time a new textline is inserted. /// </summary> /// <param name="TextA">A-version of the text (usualy the old one)</param> /// <param name="TextB">B-version of the text (usualy the new one)</param> /// <param name="trimSpace">When set to true, all leading and trailing whitespace characters are stripped out before the comparation is done.</param> /// <param name="ignoreSpace">When set to true, all whitespace characters are converted to a single space character before the comparation is done.</param> /// <param name="ignoreCase">When set to true, all characters are converted to their lowercase equivivalence before the comparation is done.</param> /// <returns>Returns a array of Items that describe the differences.</returns> public static Item [] DiffText(string TextA, string TextB, bool trimSpace, bool ignoreSpace, bool ignoreCase) { // prepare the input-text and convert to comparable numbers. Hashtable h = new Hashtable(TextA.Length + TextB.Length); // The A-Version of the data (original data) to be compared. DiffData DataA = new DiffData(DiffCodes(TextA, h, trimSpace, ignoreSpace, ignoreCase)); // The B-Version of the data (modified data) to be compared. DiffData DataB = new DiffData(DiffCodes(TextB, h, trimSpace, ignoreSpace, ignoreCase)); h = null; // free up hashtable memory (maybe) LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length); return CreateDiffs(DataA, DataB); } // DiffText /// <summary> /// Find the difference in 2 arrays of integers. /// </summary> /// <param name="ArrayA">A-version of the numbers (usualy the old one)</param> /// <param name="ArrayB">B-version of the numbers (usualy the new one)</param> /// <returns>Returns a array of Items that describe the differences.</returns> public static Item [] DiffInt(int[] ArrayA, int[] ArrayB) { // The A-Version of the data (original data) to be compared. DiffData DataA = new DiffData(ArrayA); // The B-Version of the data (modified data) to be compared. DiffData DataB = new DiffData(ArrayB); LCS(DataA, 0, DataA.Length, DataB, 0, DataB.Length); return CreateDiffs(DataA, DataB); } // Diff /// <summary> /// This function converts all textlines of the text into unique numbers for every unique textline /// so further work can work only with simple numbers. /// </summary> /// <param name="aText">the input text</param> /// <param name="h">This extern initialized hashtable is used for storing all ever used textlines.</param> /// <param name="trimSpace">ignore leading and trailing space characters</param> /// <returns>a array of integers.</returns> private static int[] DiffCodes(string aText, Hashtable h, bool trimSpace, bool ignoreSpace, bool ignoreCase) { // get all codes of the text string []Lines; int []Codes; int lastUsedCode = h.Count; object aCode; string s; // strip off all cr, only use lf as textline separator. aText = aText.Replace("\r", ""); Lines = aText.Split('\n'); Codes = new int[Lines.Length]; for (int i = 0; i < Lines.Length; ++i) { s = Lines[i]; if (trimSpace) s = s.Trim(); if (ignoreSpace) { s = Regex.Replace(s, "\\s+", " "); // TODO: optimization: faster blank removal. } if (ignoreCase) s = s.ToLower(); aCode = h[s]; if (aCode == null) { lastUsedCode++; h[s] = lastUsedCode; Codes[i] = lastUsedCode; } else { Codes[i] = (int)aCode; } // if } // for return(Codes); } // DiffCodes /// <summary> /// This is the algorithm to find the Shortest Middle Snake (SMS). /// </summary> /// <param name="DataA">sequence A</param> /// <param name="LowerA">lower bound of the actual range in DataA</param> /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param> /// <param name="DataB">sequence B</param> /// <param name="LowerB">lower bound of the actual range in DataB</param> /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param> /// <returns>a MiddleSnakeData record containing x,y and u,v</returns> private static SMSRD SMS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB) { SMSRD ret; int MAX = DataA.Length + DataB.Length + 1; int DownK = LowerA - LowerB; // the k-line to start the forward search int UpK = UpperA - UpperB; // the k-line to start the reverse search int Delta = (UpperA - LowerA) - (UpperB - LowerB); bool oddDelta = (Delta & 1) != 0; /// vector for the (0,0) to (x,y) search int[] DownVector = new int[2* MAX + 2]; /// vector for the (u,v) to (N,M) search int[] UpVector = new int[2 * MAX + 2]; // The vectors in the publication accepts negative indexes. the vectors implemented here are 0-based // and are access using a specific offset: UpOffset UpVector and DownOffset for DownVektor int DownOffset = MAX - DownK; int UpOffset = MAX - UpK; int MaxD = ((UpperA - LowerA + UpperB - LowerB) / 2) + 1; // Debug.Write(2, "SMS", String.Format("Search the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB)); // init vectors DownVector[DownOffset + DownK + 1] = LowerA; UpVector[UpOffset + UpK - 1] = UpperA; for (int D = 0; D <= MaxD; D++) { // Extend the forward path. for (int k = DownK - D; k <= DownK + D; k += 2) { // Debug.Write(0, "SMS", "extend forward path " + k.ToString()); // find the only or better starting point int x, y; if (k == DownK - D) { x = DownVector[DownOffset + k+1]; // down } else { x = DownVector[DownOffset + k-1] + 1; // a step to the right if ((k < DownK + D) && (DownVector[DownOffset + k+1] >= x)) x = DownVector[DownOffset + k+1]; // down } y = x - k; // find the end of the furthest reaching forward D-path in diagonal k. while ((x < UpperA) && (y < UpperB) && (DataA.data[x] == DataB.data[y])) { x++; y++; } DownVector[DownOffset + k] = x; // overlap ? if (oddDelta && (UpK-D < k) && (k < UpK+D)) { if (UpVector[UpOffset + k] <= DownVector[DownOffset + k]) { ret.x = DownVector[DownOffset + k]; ret.y = DownVector[DownOffset + k] - k; // ret.u = UpVector[UpOffset + k]; // 2002.09.20: no need for 2 points // ret.v = UpVector[UpOffset + k] - k; return (ret); } // if } // if } // for k // Extend the reverse path. for (int k = UpK - D; k <= UpK + D; k += 2) { // Debug.Write(0, "SMS", "extend reverse path " + k.ToString()); // find the only or better starting point int x, y; if (k == UpK + D) { x = UpVector[UpOffset + k-1]; // up } else { x = UpVector[UpOffset + k+1] - 1; // left if ((k > UpK - D) && (UpVector[UpOffset + k-1] < x)) x = UpVector[UpOffset + k-1]; // up } // if y = x - k; while ((x > LowerA) && (y > LowerB) && (DataA.data[x-1] == DataB.data[y-1])) { x--; y--; // diagonal } UpVector[UpOffset + k] = x; // overlap ? if (! oddDelta && (DownK-D <= k) && (k <= DownK+D)) { if (UpVector[UpOffset + k] <= DownVector[DownOffset + k]) { ret.x = DownVector[DownOffset + k]; ret.y = DownVector[DownOffset + k] - k; // ret.u = UpVector[UpOffset + k]; // 2002.09.20: no need for 2 points // ret.v = UpVector[UpOffset + k] - k; return (ret); } // if } // if } // for k } // for D throw new ApplicationException("the algorithm should never come here."); } // SMS /// <summary> /// This is the divide-and-conquer implementation of the longes common-subsequence (LCS) /// algorithm. /// The published algorithm passes recursively parts of the A and B sequences. /// To avoid copying these arrays the lower and upper bounds are passed while the sequences stay constant. /// </summary> /// <param name="DataA">sequence A</param> /// <param name="LowerA">lower bound of the actual range in DataA</param> /// <param name="UpperA">upper bound of the actual range in DataA (exclusive)</param> /// <param name="DataB">sequence B</param> /// <param name="LowerB">lower bound of the actual range in DataB</param> /// <param name="UpperB">upper bound of the actual range in DataB (exclusive)</param> private static void LCS(DiffData DataA, int LowerA, int UpperA, DiffData DataB, int LowerB, int UpperB) { // Debug.Write(2, "LCS", String.Format("Analyse the box: A[{0}-{1}] to B[{2}-{3}]", LowerA, UpperA, LowerB, UpperB)); // Fast walkthrough equal lines at the start while (LowerA < UpperA && LowerB < UpperB && DataA.data[LowerA] == DataB.data[LowerB]) { LowerA++; LowerB++; } // Fast walkthrough equal lines at the end while (LowerA < UpperA && LowerB < UpperB && DataA.data[UpperA-1] == DataB.data[UpperB-1]) { --UpperA; --UpperB; } if (LowerA == UpperA) { // mark as inserted lines. while (LowerB < UpperB) DataB.modified[LowerB++] = true; } else if (LowerB == UpperB) { // mark as deleted lines. while (LowerA < UpperA) DataA.modified[LowerA++] = true; } else { // Find the middle snakea and length of an optimal path for A and B SMSRD smsrd = SMS(DataA, LowerA, UpperA, DataB, LowerB, UpperB); // Debug.Write(2, "MiddleSnakeData", String.Format("{0},{1}", smsrd.x, smsrd.y)); // The path is from LowerX to (x,y) and (x,y) ot UpperX LCS(DataA, LowerA, smsrd.x, DataB, LowerB, smsrd.y); LCS(DataA, smsrd.x, UpperA, DataB, smsrd.y, UpperB); // 2002.09.20: no need for 2 points } } // LCS() /// <summary>Scan the tables of which lines are inserted and deleted, /// producing an edit script in forward order. /// </summary> /// dynamic array private static Item[] CreateDiffs(DiffData DataA, DiffData DataB) { ArrayList a = new ArrayList(); Item aItem; Item []result; int StartA, StartB; int LineA, LineB; LineA = 0; LineB = 0; while (LineA < DataA.Length || LineB < DataB.Length) { if ((LineA < DataA.Length) && (! DataA.modified[LineA]) && (LineB < DataB.Length) && (! DataB.modified[LineB])) { // equal lines LineA++; LineB++; } else { // maybe deleted and/or inserted lines StartA = LineA; StartB = LineB; while (LineA < DataA.Length && (LineB >= DataB.Length || DataA.modified[LineA])) // while (LineA < DataA.Length && DataA.modified[LineA]) LineA++; while (LineB < DataB.Length && (LineA >= DataA.Length || DataB.modified[LineB])) // while (LineB < DataB.Length && DataB.modified[LineB]) LineB++; if ((StartA < LineA) || (StartB < LineB)) { // store a new difference-item aItem = new Item(); aItem.StartA = StartA; aItem.StartB = StartB; aItem.deletedA = LineA - StartA; aItem.insertedB = LineB - StartB; a.Add(aItem); } // if } // if } // while result = new Item[a.Count]; a.CopyTo(result); return (result); } } // class Diff /// <summary>Data on one input file being compared. /// </summary> internal class DiffData { /// <summary>Number of elements (lines).</summary> internal int Length; /// <summary>Buffer of numbers that will be compared.</summary> internal int[] data; /// <summary> /// Array of booleans that flag for modified data. /// This is the result of the diff. /// This means deletedA in the first Data or inserted in the second Data. /// </summary> internal bool[] modified; /// <summary> /// Initialize the Diff-Data buffer. /// </summary> /// <param name="data">reference to the buffer</param> internal DiffData(int[] initData) { data = initData; Length = initData.Length; modified = new bool[Length + 2]; } // DiffData } // class DiffData } // namespace
会继续再试,有新进展会贴上来 ^_^
发表评论
-
Ganymed Study
2012-07-19 00:54 8511. Website http://www.gany ... -
Netty Study
2012-05-07 19:04 785Let -
FilteredFilesGenerator
2012-01-02 20:58 0A tool to generate some fileted ... -
abc
2011-11-17 22:47 0姓名 性别 上次党费缴纳至 本次党费缴纳至 计算 月份 ... -
巧妙的位运算及模运算
2010-12-29 15:02 1866原帖:http://www.lgsee.com/?p= ... -
diff tool
2010-04-13 22:52 926package processor; public cl ... -
关于Java thread的Interrupt, isInterrupt, interrupted
2009-12-26 00:58 10230在《Java网络编程》上看到一个例子, 说是用thread.i ... -
在UltraEdit的查找和替换中使用正则表达式 (转)
2009-08-12 14:22 929转自http://baizheng.iteye.com/blo ... -
Java Swing 组件全演示
2009-05-04 16:57 2301从http://www.hackhome.com/InfoVi ... -
java--swing在文本框显示某txt文件内容..
2009-05-04 16:53 6874从http://qzone.qq.com/blog/12082 ... -
动手实践制作双击运行jar包
2009-05-03 14:43 2288这几天帮大学同学的女朋友做了一个毕业设计 , 是一个什么什么库 ... -
JAR文件包及jar命令详解
2009-05-03 00:58 822引用JAR文件包及jar命令 ...
相关推荐
Java常用类与基础API--String常见算法题目
本文将详细讨论如何在C++中将`double`类型的数值转换为`std::string`字符串,以及如何将`std::string`转换回`double`。我们将基于提供的`stringtodouble`工程文件进行讨论。 首先,让我们探讨`double`转`string`的...
在C++中实现这些算法,我们需要定义字符串类或者使用标准库中的`std::string`,并结合循环和条件判断实现匹配逻辑。`matching.cpp`和`matching.h`文件可能包含了这些算法的实现代码,如定义函数或类来封装匹配过程,...
这个"477.475.JAVA基础教程_常用类-String课后算法题目3(477).rar"文件很可能是一个Java基础教学资料,特别关注了String类的使用以及相关的算法实践。String类在Java中扮演着核心角色,因为处理文本数据时我们经常...
计算机后端-Java-Java核心基础-第22章 常用类 05. String课后算法题目1.avi
计算机后端-Java-Java核心基础-第22章 常用类 06. String课后算法题目2.avi
计算机后端-Java-Java核心基础-第22章 常用类 07. String课后算法题目3.avi
计算机后端-Java-Java核心基础-第22章 常用类 08. String课后算法题目3拓展.avi
java-string-similarity, 各种字符串相似性和距离算法 java-string-similarity 实现不同字符串相似度和距离度量的库。 目前已经实现了许多算法( 包括Levenshtein编辑距离和 sibblings,jaro winkler,最长公共子序列...
string算法题(俩个).pdf
**KMP算法详解** KMP(Knuth-Morris-Pratt)算法是一种高效的字符串匹配算法,由D.E. Knuth、V.R. Morris和J.H. Pratt于1977年提出。它解决了在一个主串(文本串)中查找一个模式串(目标串)的问题,避免了在匹配...
string、CString 和 char* 都提供了多种常用算法,如查找、比较等。 * 查找算法,如 strchr、strstr、strrchr 等,可以在字符串中查找指定的值。 * 比较算法,如 strcmp、strncmp、strcoll 等,可以比较字符串的...
string_vector_set_算法相关总结 本文总结了 string、vector、set 等数据结构的使用和算法相关知识点,涵盖了字符串的转换、替换、查找、距离计算、树的遍历、链表的操作、除法运算的优化、vector 的使用、...
在"Communications of the Association for Computing Machinery"杂志上发表的论文"A Fast String Searching Algorithm"详细阐述了这一算法。BM算法的核心思想是利用坏字符规则和好后缀规则来避免不必要的字符比较,...
"实现string算法的魔鬼曲线"是一个有趣的编程话题,它涉及到计算机图形学和分形几何领域。魔鬼曲线(Dragon Curve)是一种著名的分形图案,它的生成过程可以通过字符串算法来实现。让我们深入探讨一下这个主题。 ...
一本全面彻底讲解字符串查找算法的书。 书中讲解了34个字符串查找算法的思想。每个算法都有适用性的描述。每个算法都有逐步推演的例子(图解)。每个算法都有代码(C语言)。每个算法都有复杂度分析。每个算法都有...
集成了大整数的、加法、减法(仅限被减数大于减数)、乘法、乘以2、除以2、减去1、判断奇偶、判断是否为1等方法 乘法和加法经过多次测试和修改,基本上不存在什么问题,...可以用到大数算法中农夫算法、蛮力算法等等。
list some String Hash algorithm, you can use it directly.
### 数据结果 KMP算法实验报告 #### 实验背景与目的 本实验主要针对《数据结构》课程中的字符串处理部分,具体涉及的是模式匹配算法——KMP算法。通过实验加深学生对串类型及其基本操作的理解,并重点掌握两种重要...