How to resolve the algorithm Ordered words step by step in the Gambas programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Ordered words step by step in the Gambas programming language
Table of Contents
Problem Statement
An ordered word is a word in which the letters appear in alphabetic order.
Examples include abbey and dirt.
Find and display all the ordered words in the dictionary unixdict.txt that have the longest word length.
(Examples that access the dictionary file locally assume that you have downloaded this file yourself.)
The display needs to be shown on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Ordered words step by step in the Gambas programming language
Source code in the gambas programming language
Public Sub Main()
Dim sDict As String = File.Load(User.Home &/ "unixdict.txt") 'Store the 'Dictionary'
Dim sOrdered As New String[] 'To store ordered words
Dim sHold As New String[] 'General store
Dim sTemp As String 'Temp variable
Dim siCount As Short 'Counter
For Each sTemp In Split(sDict, gb.NewLine) 'For each word in the Dictionary
For siCount = 1 To Len(sTemp) 'Loop for each letter in the word
sHold.Add(Mid(sTemp, siCount, 1)) 'Put each letter in sHold array
Next
sHold.Sort() 'Sort sHold (abbott = abboot, zoom = mooz)
If sTemp = sHold.Join("") Then sOrdered.Add(sTemp) 'If they are the same (abbott(OK) mooz(not OK)) then add to sOrdered
sHold.Clear 'Empty sHold
Next
siCount = 0 'Reset siCount
For Each sTemp In sOrdered 'For each of the Ordered words
If Len(sTemp) > siCount Then siCount = Len(sTemp) 'Count the length of the word and keep a record of the longest length
Next
For Each sTemp In sOrdered 'For each of the Ordered words
If Len(sTemp) = siCount Then sHold.Add(sTemp) 'If it is one of the longest add it to sHold
Next
sHold.Sort() 'Sort sHold
Print sHold.Join(gb.NewLine) 'Display the result
End
You may also check:How to resolve the algorithm Leap year step by step in the Julia programming language
You may also check:How to resolve the algorithm Knapsack problem/Unbounded step by step in the R programming language
You may also check:How to resolve the algorithm Real constants and functions step by step in the Asymptote programming language
You may also check:How to resolve the algorithm Parsing/RPN calculator algorithm step by step in the Scala programming language
You may also check:How to resolve the algorithm Water collected between towers step by step in the jq programming language