parent
41edff5d32
commit
9dc73e73af
@ -0,0 +1,42 @@
|
|||||||
|
open System
|
||||||
|
|
||||||
|
let readStringList () =
|
||||||
|
let rec readLines acc =
|
||||||
|
let line = Console.ReadLine()
|
||||||
|
if String.IsNullOrEmpty(line) then
|
||||||
|
List.rev acc
|
||||||
|
else
|
||||||
|
readLines (line :: acc)
|
||||||
|
readLines []
|
||||||
|
|
||||||
|
let sortByLength strings =
|
||||||
|
strings |> List.sortBy (fun s -> s.Length)
|
||||||
|
|
||||||
|
let printStringList strings =
|
||||||
|
strings |> List.iter (fun s -> printfn "%s" s)
|
||||||
|
|
||||||
|
let demonstrateWithSample () =
|
||||||
|
let sampleStrings = ["hello"; "world"; "a"; "programming"; "test"]
|
||||||
|
printfn "Original list:"
|
||||||
|
printStringList sampleStrings
|
||||||
|
printfn "\nSorted by length:"
|
||||||
|
let sorted = sortByLength sampleStrings
|
||||||
|
printStringList sorted
|
||||||
|
|
||||||
|
[<EntryPoint>]
|
||||||
|
let main argv =
|
||||||
|
printfn "Enter strings (empty line to finish):"
|
||||||
|
let strings = readStringList ()
|
||||||
|
|
||||||
|
if List.isEmpty strings then
|
||||||
|
printfn "No strings entered. Using sample data:"
|
||||||
|
demonstrateWithSample ()
|
||||||
|
else
|
||||||
|
printfn "\nOriginal strings:"
|
||||||
|
printStringList strings
|
||||||
|
|
||||||
|
printfn "\nSorted by length:"
|
||||||
|
let sortedStrings = sortByLength strings
|
||||||
|
printStringList sortedStrings
|
||||||
|
|
||||||
|
0
|
@ -0,0 +1,8 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
Reference in new issue