How to resolve the algorithm Determine if a string has all the same characters step by step in the Maple programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Determine if a string has all the same characters step by step in the Maple programming language
Table of Contents
Problem Statement
Given a character string (which may be empty, or have a length of zero characters):
Use (at least) these seven test values (strings):
Show all output here on this page.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Determine if a string has all the same characters step by step in the Maple programming language
Source code in the maple programming language
CheckSame:=proc(s)
local i, index;
printf("input: \"%s\", length: %a\n", s, StringTools:-Length(s));
for i from 2 to StringTools:-Length(s) do
if (s[i - 1] <> s[i]) then
printf("The given string has different characters.\n");
printf("The first different character is %a (0x%x) which appears at index %a.\n\n",
s[i], convert(s[i], 'bytes')[1], i);
return;
end if;
end do;
# if no difference found
printf("The given string has all same characters.\n\n");
end proc:
# Test
CheckSame("");
CheckSame(" ");
CheckSame("2");
CheckSame("333");
CheckSame(".55");
CheckSame("tttTTT");
CheckSame("4444 444k");
You may also check:How to resolve the algorithm Catalan numbers/Pascal's triangle step by step in the Go programming language
You may also check:How to resolve the algorithm Cholesky decomposition step by step in the J programming language
You may also check:How to resolve the algorithm Environment variables step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Gray code step by step in the C++ programming language
You may also check:How to resolve the algorithm Terminal control/Preserve screen step by step in the Perl programming language