Author Topic: Find and Show the longest ordered words of the file unixdict.txt (Rosetta Code)  (Read 2834 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Hi
another task of Rosetta Code http://rosettacode.org/wiki/Ordered_words
and this is my solution
Code: QB64: [Select]
  1. 'Task
  2. ' Find and display all the ordered words in the dictionary   unixdict.txt
  3. ' that have the longest word length.
  4. Dim NameFile As String, NewLine As String, max As Integer, index As Integer
  5. ReDim ListWords(1 To 2) As String
  6.  
  7. NameFile = "unixdict.txt"
  8. NewLine = ""
  9. max = 0
  10. index = 0
  11. Open NameFile For Input As #1
  12.     Input #1, NewLine
  13.     If IsOrderedWord(NewLine) = -1 Then
  14.         If max = Len(NewLine) Then
  15.             index = index + 1
  16.             ReDim _Preserve ListWords(1 To index)
  17.             ListWords(index) = NewLine
  18.         ElseIf max < Len(NewLine) Then
  19.             max = Len(NewLine)
  20.             ReDim ListWords(1 To 2)
  21.             index = 1
  22.             ListWords(index) = NewLine
  23.         End If
  24.     End If
  25. For max = 1 To UBound(listwords)
  26.     Print ListWords(max)
  27.  
  28. Function IsOrderedWord (s As String)
  29.     IsOrderedWord = 0
  30.     Dim count As Integer
  31.     For count = 1 To Len(s) - 1
  32.         If Asc(s, count) > Asc(s, count + 1) Then Exit Function
  33.     Next
  34.     IsOrderedWord = -1
  35.  
  36.  
Thanks to test. Attached there is the txt file
PS I have forgotten the OrderedWords, now all is complete.
* unixdict.txt (Filesize: 226.08 KB, Downloads: 211)
« Last Edit: April 26, 2021, 06:17:43 pm by TempodiBasic »
Programming isn't difficult, only it's  consuming time and coffee