How to resolve the algorithm Reverse words in a string step by step in the Applesoft BASIC programming language
How to resolve the algorithm Reverse words in a string step by step in the Applesoft BASIC programming language
Table of Contents
Problem Statement
Reverse the order of all tokens in each of a number of strings and display the result; the order of characters within a token should not be modified.
Hey you, Bub! would be shown reversed as: Bub! you, Hey
Tokens are any non-space characters separated by spaces (formally, white-space); the visible punctuation form part of the word within which it is located and should not be modified. You may assume that there are no significant non-visible characters in the input. Multiple or superfluous spaces may be compressed into a single space. Some strings have no tokens, so an empty string (or one just containing spaces) would be the result. Display the strings in order (1st, 2nd, 3rd, ···), and one string per line. (You can consider the ten strings as ten lines, and the tokens as words.)
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Reverse words in a string step by step in the Applesoft BASIC programming language
Source code in the applesoft programming language
100 DATA"---------- ICE AND FIRE ------------"
110 DATA" "
120 DATA"FIRE, IN END WILL WORLD THE SAY SOME"
130 DATA"ICE. IN SAY SOME "
140 DATA"DESIRE OF TASTED I'VE WHAT FROM "
150 DATA"FIRE. FAVOR WHO THOSE WITH HOLD I "
160 DATA" "
170 DATA"... ELIDED PARAGRAPH LAST ... "
180 DATA" "
190 DATA"FROST ROBERT -----------------------"
200 FOR L = 1 TO 10
210 READ T$
220 I = LEN(T$)
240 IF I THEN GOSUB 300 : PRINT W$; : IF I THEN PRINT " "; : GOTO 240
250 PRINT
260 NEXT L
270 END
300 W$ = ""
310 FOR I = I TO 1 STEP -1
320 IF MID$(T$, I, 1) = " " THEN NEXT I : RETURN
330 FOR I = I TO 1 STEP -1
340 C$ = MID$(T$, I, 1)
350 IF C$ <> " " THEN W$ = C$ + W$ : NEXT I
360 RETURN
You may also check:How to resolve the algorithm FTP step by step in the Scala programming language
You may also check:How to resolve the algorithm SEDOLs step by step in the FreeBASIC programming language
You may also check:How to resolve the algorithm SHA-256 Merkle tree step by step in the Phix programming language
You may also check:How to resolve the algorithm Floyd-Warshall algorithm step by step in the Lua programming language
You may also check:How to resolve the algorithm Loops/Continue step by step in the Java programming language