KMP算法的C#实现方法

如何运用KMP算法实现C#呢?下面小编为大家整理了KMP算法的C#实现方法,希望能帮到大家!

KMP算法的C#实现方法

C#实现大数字的`运算

1、添加引用:

2、添加命名空间:using rics;

3、实例:

3.1判断一个数字是不是质数

  复制代码 代码如下:

  static void Main(string[] args)

{

eLine("请输入一个很大的数字:");

string bigNumber = Line();

BigInteger bigInteger = e(bigNumber);

bool isNumber=false;

for (BigInteger i = 2; i < (bigInteger, 2);i++ )

{

if (bigInteger % i == 0)

{

isNumber = true;

break;

}

}

if (isNumber)

{

eLine("不是质数");

}

else

{

eLine("是质数");

}

Line();

}

3.2实现两个大数的加减乘除

复制代码 代码如下:

static void Main(string[] args)

{

e("请输入第一个大数字:");

string bigNum1 = Line();

BigInteger bigInt1 = e(bigNum1);

e("请输入第二个大数字:");

string bigNum2 = Line();

BigInteger bigInt2 = e(bigNum2);

e(ine);

BigInteger addNum = bigInt1 + bigInt2;

BigInteger subNum = bigInt1 - bigInt2;

BigInteger purNum = bigInt1 * bigInt2;

BigInteger divNum = bigInt1 / bigInt2;

eLine("两大数相加结果为:{0}",addNum);

eLine("两大数相减结果为:{0}",subNum);

eLine("两大数相乘结果为:{0}",purNum);

eLine("两大数相除结果为:{0}",divNum);

Line();

}