{"title":"F# 统计区间内包含至少两个数字2的数字数量","description":"使用F#编程语言实现统计给定区间内包含至少两个数字2的数字数量。文章提供代码示例和详细解释,帮助你理解算法逻辑。","keywords":"F#, 编程语言, 统计, 区间, 数字, 算法, 代码示例, 解释","content":"open System\n\nlet input = Console.ReadLine()\nlet nums = input.Split(' ')\nlet num1 = Int32.Parse(nums.[0])\nlet num2 = Int32.Parse(nums.[1])\n\nlet ans = \n\tseq { num1..num2 }\n\t|> Seq.filter (fun x -> \n\t\tlet mutable j = x\n\t\tlet mutable countTwo = 0\n\t\twhile j > 0 do\n\t\t\tif j % 10 = 2 then\n\t\t\t\tcountTwo <- countTwo + 1\n\t\t\tj <- j / 10\n\t\tcountTwo >= 2 )\n\t|> Seq.length\nprintfn "%d" ans"}

F# 统计区间内包含至少两个数字2的数字数量

原文地址: https://www.cveoy.top/t/topic/p1Uv 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录