Write a program that takes these values to find all of
the different patterns in "input" of length "patternLength"
and output all of the patterns that occur more than once and the
number of times they occur.
For example, when searching the string
"zf3kabxcde224lkzf3mabxc51+crsdtzf3nab=", with a specified pattern
length of 3, the method should return the pattern "abx” with an
occurrence value of two, and “zf3” with an occurrence value of
three.
The answer should be written in C#,
SOURCE CODE:
*Please follow the comments to better understand the code.
**Please look at the Screenshot below and use this code to copy-paste.
***The code in the below screenshot is neatly indented for better understanding.
This is a very big question.
I have solved all of them.
Please give me an upvote dear, Much Appreciated.!!
using System;
using System.Collections.Generic;
using System.Linq;
// Create a namespace as needed
namespace DummyNameSpace
{
// Create a class
class TestProgram
{
// craete an innrer class DemoPattern
public class DemoPattern
{
// declare the variables
private string pattern;
private int count;
// Constructor here
public DemoPattern(string str, int count)
{
this.pattern = str;
this.count = count;
}
// Getters and Setters
public int Count { get => count;}
public string Pattern { get => pattern; }
// Methods
public void AddCount()
{
this.count = this.count + 1;
}
public override int GetHashCode()
{
return this.pattern.GetHashCode();
}
public override string ToString()
{
return string.Format("Pattern<{0} - {1}>", Pattern,
Count);
}
}
// Find the pettens here
public static List<DemoPattern> Find(string data, int
len)
{
var map = new Dictionary<string, DemoPattern>();
HashSet<DemoPattern> f = new
HashSet<DemoPattern>();
if (data.Length < len)
{
// no patterns found if not long enough
return f.ToList();
}
if (data.Length == len) {
// if the string is exact same length, then no need to loop
through
f.Add(new DemoPattern(data, 1));
return f.ToList();
}
/* O(n) to loop through all the characters */
for (int k = 0; k <= (data.Length - len); k++)
{
var substr = data.Substring(k, len);
/* o(1) to look up a pattern */
var mypattern = map.GetValueOrDefault(substr, null);
if (mypattern == null)
{
map.Add(substr, new DemoPattern(substr, 1));
}
else
{
mypattern.AddCount();
if (mypattern.Count > 1)
{
// this pattern has been found more than once, keep it
f.Add(mypattern);
}
}
}
/* Somewhere between O(n) and O(1) depending on how many
patterns are found) */
List<DemoPattern> patterns = f.ToList();
/* Could the set, but the list makes it easier to test */
patterns.Sort(delegate (DemoPattern x, DemoPattern y)
{
return x.Count.CompareTo(y.Count);
});
return patterns;
}
// Driver method to test the methdo we created above
static void Main(string[] args)
{
// Take DemoPattern list of objects
List<DemoPattern> patterns;
Console.WriteLine("======================TEST
1==================");
// TEST 1
patterns = Find("zf3kabxcde224lkzf3mabxc51+crsdtzf3nab", 3);
Console.WriteLine(string.Join(", ", patterns));
Console.WriteLine("======================TEST
2==================");
// TEST 2
patterns = Find("aaaa", 3);
Console.WriteLine(string.Join(", ", patterns));
Console.WriteLine("======================TEST
3==================");
// TEST 3
patterns =
Find("aaa", 1);
Console.WriteLine(string.Join(", ", patterns));
}
}
}
Write a program that takes these values to find all of the different patterns in "input"...
Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers to build a list of the specified length made up by repeating the numbers from the input list as many times as required. That is, the output list has the specified length same as the length specified by the input integer. For example: fillNum 4 [5,6,7,8,9,10] should output [5,6,7,8] fillNum 9 [4,3,2,1] should output [4,3,2,1]
Using Haskell to write a program: fillNum fillNum takes an integer and a list of numbers to build a list of the specified length made up by repeating the numbers from the input list as many times as required. That is, the output list has the specified length same as the length specified by the input integer. For example: fillNum 4 [5,6,7,8,9,10] should output [5,6,7,8] fillNum 9 [4,3,2,1] should output [4,3,2,1,4,3,2,1,4] fillNum 7 [1,2,3] should output [1,2,3,1,2,3,1]
Write a basic ARM program that takes a string as input, then outputs a string that replaces all the vowels in the input string with 'x'. Vowels: a, A, e, E, i, I, o, O, u, U. **I am using DS-5 Eclipse Community Workspace with ARM assembly language.** The program should give the following input prompt: "Input a string: " Then, the program should output the string with the vowel(s) replaced with x. The program should terminate upon printing the...
A Java Problem.
E5.19 Write a program that takes user input describing a playing card in the following shorthand notation: А Ace 2... 10 Card values Jack Queen King Diamonds Hearts Spades Clubs Your program should print the full description of the card. For example, Enter the card notation: QS Queen of Spades Implement a class Card whose constructor takes the card notation string and whose getDescription method returns a description of the card. If the notation string is not...
Write a program that takes in a line of text as input, and outputs that line of text in reverse. You may assume that each line of text will not exceed 50 characters. The program repeats, ending when the user enters "Quit", "quit", or "q" for the line of text. Ex: If the input is: Hello there Hey quit then the output is: ereht olleH уен Hint: Use the fgets function to read a string with spaces from the user...
11) Write a method (including header and body) that takes as an input an array of doubles and f three doubles containing the average, the maximum and the minimunm values of the input array. Test the program by calling the method from the main method. For example Input: 1 2 3 45 Output: 3 5 1 12) Write a Java method that takes a string as an argument and returns the reverse the string. Test the program by calling the...
Write a program that can remove spaces from an input string, find the indexes of a character within the string and replace that character with another character. Here is an example input: I am an input string a b The first line, "I am an input string" represents the input string. Please put it into a string variable using getline. In the second line "a b", a is the character that needs to be located within the input string, and...
In C language Write a program that includes a function search() that finds the index of the first element of an input array that contains the value specified. n is the size of the array. If no element of the array contains the value, then the function should return -1. The program takes an int array, the number of elements in the array, and the value that it searches for. The main function takes input, calls the search()function, and displays...
2a) Write a method countEvens that takes an ArrayList of String objects as input and returns the number of even length strings contained in the input. For example, if the input is [ one, peach, pear, plum ] then countEvents(inp) should return 2. 2b) Write a method, mirror, that doubles the size of a list of integers by appending a mirror image of the list. For example, given an array list containing [ 1, 5, 2, 6 ], the method...
FOR JAVA Write a program that takes two command line arguments: an input file and an output file. The program should read the input file and replace the last letter of each word with a * character and write the result to the output file. The program should maintain the input file's line separators. The program should catch all possible checked exceptions and display an informative message. Notes: This program can be written in a single main method Remember that...