标签:style class blog code http color
using System; namespace ConsoleApplication10 { class Program { static void Main(string[] args) { Console.WriteLine(index("cbbcbcbb","acbc")); Console.WriteLine(index("cbbcbcbb","bcb")); Console.ReadLine(); } static int index(string s ,string t) { int i = 0, j = 0, k; while (i<s.Length&&j<t.Length) { if (s[i]==t[j]) {//如果相等继续匹配 i++; j++; } else {//不相等时回溯 i = i - j + 1; j = 0; } } if (j>=t.Length) {//匹配成功 k = i - t.Length; } else { k=-1; } return k; } } }
标签:style class blog code http color
原文地址:http://www.cnblogs.com/liek/p/3807051.html