How to resolve the algorithm Determine if a string has all the same characters step by step in the XPL0 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 XPL0 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 XPL0 programming language

Source code in the xpl0 programming language

include xpllib;                 \contains StrLen function

proc    StrSame(S);             \Show if string has same characters
char    S;
int     L, I, J, K;
[L:= StrLen(S);
IntOut(0, L);  Text(0, ":       ^"");  Text(0, S);  ChOut(0, ^");  CrLf(0);
for I:= 0 to L-1 do
    for J:= I+1 to L-1 do
        [if S(I) # S(J) then
                [ChOut(0, \tab\ 9);
                for K:= 0 to J do ChOut(0, ^ );
                Text(0, "^^ Not same character: ");
                ChOut(0, S(J));
                Text(0, ", hex ");
                SetHexDigits(2);
                HexOut(0, S(J));
                CrLf(0);
                return;
                ];
        ];
Text(0, "       All same character");  CrLf(0);
];

[Text(0, "Length");  CrLf(0);
StrSame("");
StrSame("   ");
StrSame("2");
StrSame("333");
StrSame(".55");
StrSame("tttTTT");
StrSame("4444 444k");
]

  

You may also check:How to resolve the algorithm Thue-Morse step by step in the Ada programming language
You may also check:How to resolve the algorithm Left factorials step by step in the C# programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the make programming language
You may also check:How to resolve the algorithm Knight's tour step by step in the Elm programming language
You may also check:How to resolve the algorithm Flatten a list step by step in the ALGOL 68 programming language