langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
43
Task/Ordered-words/PureBasic/ordered-words.purebasic
Normal file
43
Task/Ordered-words/PureBasic/ordered-words.purebasic
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
Procedure.s sortLetters(*word.Character, wordLength) ;returns a string with the letters of a word sorted
|
||||
Protected Dim letters.c(wordLength)
|
||||
Protected *letAdr = @letters()
|
||||
|
||||
CopyMemoryString(*word, @*letAdr)
|
||||
SortArray(letters(), #PB_Sort_Ascending, 0, wordLength - 1)
|
||||
ProcedureReturn PeekS(@letters(), wordLength)
|
||||
EndProcedure
|
||||
|
||||
Structure orderedWord
|
||||
word.s
|
||||
length.i
|
||||
EndStructure
|
||||
|
||||
Define filename.s = "unixdict.txt", fileNum = 0, word.s
|
||||
|
||||
If OpenConsole()
|
||||
NewList orderedWords.orderedWord()
|
||||
If ReadFile(fileNum, filename)
|
||||
While Not Eof(fileNum)
|
||||
word = ReadString(fileNum)
|
||||
If word = sortLetters(@word, Len(word))
|
||||
AddElement(orderedWords())
|
||||
orderedWords()\word = word
|
||||
orderedWords()\length = Len(word)
|
||||
EndIf
|
||||
Wend
|
||||
EndIf
|
||||
|
||||
SortStructuredList(orderedWords(), #PB_Sort_Ascending, OffsetOf(orderedWord\word), #PB_Sort_String)
|
||||
SortStructuredList(orderedWords(), #PB_Sort_Descending, OffsetOf(orderedWord\length), #PB_Sort_integer)
|
||||
Define maxLength
|
||||
FirstElement(orderedWords())
|
||||
maxLength = orderedWords()\length
|
||||
ForEach orderedWords()
|
||||
If orderedWords()\length = maxLength
|
||||
Print(orderedWords()\word + " ")
|
||||
EndIf
|
||||
Next
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit"): Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
Loading…
Add table
Add a link
Reference in a new issue