How to resolve the algorithm Compare length of two strings step by step in the MiniScript programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Compare length of two strings step by step in the MiniScript programming language
Table of Contents
Problem Statement
Given two strings of different length, determine which string is longer or shorter. Print both strings and their length, one on each line. Print the longer one first. Measure the length of your string in terms of bytes or characters, as appropriate for your language. If your language doesn't have an operator for measuring the length of a string, note it. Given more than two strings: list = ["abcd","123456789","abcdef","1234567"] Show the strings in descending length order.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Compare length of two strings step by step in the MiniScript programming language
Source code in the miniscript programming language
// Simple version
print "Simple version:"
s2 = "This is the first string."
s1 = "This is string number two."
if s1.len > s2.len then
print s1.len + ": " + s1
print s2.len + ": " + s2
else
print s2.len + ": " + s2
print s1.len + ": " + s1
end if
// Extra credit. More than 2 strings
strings = ["qwerty", "abc", "#FFFFFFFF", "255,255,255,255", "3.14159"]
pairs = []
for string in strings
pairs.push([string, string.len])
end for
// sort by index descending
pairs.sort(1, false)
print
print "Extra credit:"
for pair in pairs
print pair[1] + ": " + pair[0]
end for
You may also check:How to resolve the algorithm Loops/Break step by step in the Yabasic programming language
You may also check:How to resolve the algorithm Call a function in a shared library step by step in the Racket programming language
You may also check:How to resolve the algorithm Generic swap step by step in the Common Lisp programming language
You may also check:How to resolve the algorithm Animation step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Pig the dice game step by step in the FOCAL programming language