How to resolve the algorithm Ordered words step by step in the VBScript programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Ordered words step by step in the VBScript 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 VBScript programming language

Source code in the vbscript programming language

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set infile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" &_
			"unixdict.txt",1)
list = ""
length = 0

Do Until inFile.AtEndOfStream
	line = infile.ReadLine
	If IsOrdered(line) Then
		If Len(line) > length Then
			length = Len(line)
			list = line & vbCrLf
		ElseIf Len(line) = length Then
			list = list & line & vbCrLf
		End If
	End If
Loop

WScript.StdOut.Write list

Function IsOrdered(word)
	IsOrdered = True
	prev_val = 0
	For i = 1 To Len(word)
		If i = 1 Then
			prev_val = Asc(Mid(word,i,1))
		ElseIf Asc(Mid(word,i,1)) >= prev_val Then
			prev_val = Asc(Mid(word,i,1))
		Else
			IsOrdered = False
			Exit For
		End If
	Next
End Function

  

You may also check:How to resolve the algorithm Church numerals step by step in the Racket programming language
You may also check:How to resolve the algorithm Amicable pairs step by step in the Pascal programming language
You may also check:How to resolve the algorithm Abstract type step by step in the DWScript programming language
You may also check:How to resolve the algorithm Knapsack problem/0-1 step by step in the C_sharp programming language
You may also check:How to resolve the algorithm Read entire file step by step in the C programming language