110,548
社区成员
发帖
与我相关
我的任务
分享
//降序,长度至少为3
using System;
public class Test
{
public static int[,] dfa = new int[128,128];
public static void init()
{
for (int i = '1'; i <= '9'; ++i)
{
dfa[i,i-1] = i-1;
dfa[0,i] = i;
}
}
public static void match(String str)
{
int state = 0;
int last = 0;
for (int i = 0;; ++i)
{
if (i == str.Length)
{
if (i-last>=3)
{
for (int j = last; j < i; ++j) Console.Write("{0}", str[j]);
Console.WriteLine("");
}
break;
}
char c = str[i];
if (dfa[state,c] == 0)
{
if (i-last>=3)
{
for (int j = last; j < i; ++j) Console.Write("{0}", str[j]);
Console.WriteLine("");
}
if (c >= '0' && c <= '9')
{
state = c;last = i;
}
else
{
state = 0;last = i + 1;
}
}
else
{
state = dfa[state,c];
}
}
Console.WriteLine("");
}
static void Main()
{
init();
match("abc321abc123456789123465");
match("123a1bc321abc1234567891234656565");
match("9876543210,987654321,98765432,9876543,987654,98765,9876,987,876543210,87654321,8765432,876543,87654,8765,876,76543210,7654321,765432,76543,7654,765,6543210,654321,65432,6543,654,543210,54321,5432,543,43210,4321,432,3210,321,210");
}
}
//降序的...
using System;
public class Test
{
public static int[,] dfa = new int[128,128];
public static void init()
{
for (int i = '1'; i <= '9'; ++i)
{
dfa[i,i-1] = i-1;
dfa[0,i] = i;
}
}
public static void match(String str)
{
int state = 0;
int last = 0;
for (int i = 0;; ++i)
{
if (i == str.Length)
{
if (i>last)
{
for (int j = last; j < i; ++j) Console.Write("{0}", str[j]);
Console.WriteLine("");
}
break;
}
char c = str[i];
if (dfa[state,c] == 0)
{
if (i>last)
{
for (int j = last; j < i; ++j) Console.Write("{0}", str[j]);
Console.WriteLine("");
}
if (c >= '0' && c <= '9')
{
state = c;last = i;
}
else
{
state = 0;last = i + 1;
}
}
else
{
state = dfa[state,c];
}
}
Console.WriteLine("");
}
static void Main()
{
init();
match("abc123abc123456789123465");
match("123a1bc123abc1234567891234656565");
match("9876543210,987654321,98765432,9876543,987654,98765,9876,987,876543210,87654321,8765432,876543,87654,8765,876,76543210,7654321,765432,76543,7654,765,6543210,654321,65432,6543,654,543210,54321,5432,543,43210,4321,432,3210,321,210");
}
}
//不会C#,改得有点差,还算编译通过了...
using System;
public class Test
{
public static int[,] dfa = new int[128,128];
public static void init()
{
for (int i = '0'; i < '9'; ++i)
{
dfa[i,i+1] = i+1;
dfa[0,i] = i;
}
}
public static void match(String str)
{
int state = 0;
int last = 0;
for (int i = 0;; ++i)
{
if (i == str.Length)
{
if (i>last)
{
for (int j = last; j < i; ++j) Console.Write("{0}", str[j]);
Console.WriteLine("");
}
break;
}
char c = str[i];
if (dfa[state,c] == 0)
{
if (i>last)
{
for (int j = last; j < i; ++j) Console.Write("{0}", str[j]);
Console.WriteLine("");
}
if (c >= '0' && c <= '9')
{
state = c;last = i;
}
else
{
state = 0;last = i + 1;
}
}
else
{
state = dfa[state,c];
}
}
Console.WriteLine("");
}
static void Main()
{
init();
match("abc123abc123456789123465");
match("123a1bc123abc1234567891234656565");
}
}
//修正下bug
Regex objRegex = new Regex(@"(?<=\D|^)(?:(?:9(?=8|\D|$))?(?:8(?=7|\D|$))?(?:7(?=6|\D|$))?(?:6(?=5|\D|$))?(?:5(?=4|\D|$))?(?:4(?=3|\D|$))?(?:3(?=2|\D|$))?(?:2(?=1|\D|$))?(?:1(?=0|\D|$))?(?:0(?=\D|$))?)(?=\D|$)");