Question: If i wanted to search a pattern in a string and trying to see if the pattern matches the string at a percent comparison, how

If i wanted to search a pattern in a string and trying to see if the pattern matches the string at a percent comparison, how can i pubish the results in a format that would allow to seperate the types of results. Code below. ie

50% of pattern has matched:

60% of pattern has matched:

70% of pattern has matched:

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;

public class Program { string s; string pattern; const double percent = .5;

public Program(string name) {

}

public void InputPattern() { Console.WriteLine("Enter the pattern you want to search: "); pattern = (Console.ReadLine()).ToUpper(); //read user input

pattern = pattern.Substring((int)(pattern.Length / 2), (int)(pattern.Length / 2));

//pattern = pattern.Substring((int)(pattern.Length * .4), (int)(pattern.Length * .6));

//pattern = pattern.Substring((int)(pattern.Length * .3), (int)(pattern.Length * .7));

//pattern = pattern.Substring((int)(pattern.Length * .2), (int)(pattern.Length * .8));

//pattern = pattern.Substring((int)(pattern.Length * .1), (int)(pattern.Length * .9));

} public void RandomGenerator() { Random geneSequence = new Random(); // The random number sequence

for (int i = 0; i < 100; i++) { int x = geneSequence.Next(1, 4);

switch (x) { case 1: s = s + 'C'; break;

case 2: s = s + 'T'; break;

case 3: s = s + 'A'; break;

case 4: s = s + 'G'; break; }

}

Console.WriteLine(s); //display results of string }

public void Search() // s is string sequence, pattern is what is inputted from user { List retVal = new List();

// boyer moore algorithm is executed here int n; n = s.Length;

int m; m = pattern.Length;

int[] badChar = new int[256];

BadCharHeuristic(pattern, m, ref badChar);

int i = 0;

while (i <= (n - m)) { int j = m - 1;

while (j >= 0 && pattern[j] == s[i + j]) --j;

if (j < 0) { retVal.Add(i); i += (i + m < n) ? m - badChar[s[i + m]] : 1; }

else { i += Math.Max(1, j - badChar[s[i + j]]); }

}

Console.WriteLine("Pattern: " + pattern);

foreach (var x in retVal) { Console.WriteLine("Pattern found at:{0}", x); } Console.WriteLine("");

}

private static void BadCharHeuristic(string str, int size, ref int[] badChar) { int i;

for (i = 0; i < 256; i++) badChar[i] = -1;

for (i = 0; i < size; i++) badChar[(int)str[i]] = i; }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!