我在网上找到了一个有趣的f#项目,它的想法是找到给定字符串中子字符串的数量。
以下是提示:
无论如何,如果有人能帮我解决这个问题,我将不胜感激。
提前致谢。
以下是提示:
Description:
You are given a DNA sequence:
a string that contains only characters 'A', 'C', 'G', and 'T'.
Your task is to calculate the number of substrings of sequence,
in which each of the symbols appears the same number of times.
Example 1:
For sequence = "ACGTACGT", the output should be 6
All substrings of length 4 contain each symbol exactly once (+5),
and the whole sequence contains each symbol twice (+1).
Example 2:
For sequence = "AAACCGGTTT", the output should be 1
Only substring "AACCGGTT" satisfies the criterion above: it contains each symbol twice.
Input: String, a sequence that consists only of symbols 'A', 'C', 'G', and 'T'.
Length constraint: 0 < sequence.length < 100000.
Output: Integer, the number of substrings where each symbol appears equally many times.
我不确定该怎么做,具体来说是不知道该去哪里。我在互联网上查找了相关信息,只找到了以下代码(我添加了输入变量、var变量,并将“things”显示为input再搜索子字符串(希望这样说起来有意义)):
open System
let countSubstring (where :string) (what : string) =
match what with
| "" -> 0
| _ -> (where.Length - where.Replace(what, @"").Length) / what.Length
[<EntryPoint>]
let main argv =
let input = System.Console.ReadLine();
let var = input.Length;
Console.WriteLine(var);
let show where what =
printfn @"countSubstring(""%s"", ""%s"") = %d" where what (countSubstring where what)
show input "ACGT"
show input "CGTA"
show input "GTAC"
show input "TACG"
0
无论如何,如果有人能帮我解决这个问题,我将不胜感激。
提前致谢。