tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,66 @@
|
|||
Procedure.s RLDecode(toDecode.s)
|
||||
Protected.s repCount, output, currChar, tmp
|
||||
Protected *c.Character = @toDecode
|
||||
|
||||
While *c\c <> #Null
|
||||
currChar = Chr(*c\c)
|
||||
Select *c\c
|
||||
Case '0' To '9'
|
||||
repCount + currChar
|
||||
Default
|
||||
If repCount
|
||||
tmp = Space(Val(repCount))
|
||||
ReplaceString(tmp, " ", currChar, #PB_String_InPlace)
|
||||
output + tmp
|
||||
repCount = ""
|
||||
Else
|
||||
output + currChar
|
||||
EndIf
|
||||
EndSelect
|
||||
*c + SizeOf(Character)
|
||||
Wend
|
||||
|
||||
ProcedureReturn output
|
||||
EndProcedure
|
||||
|
||||
Procedure.s RLEncode(toEncode.s)
|
||||
Protected.s currChar, prevChar, output
|
||||
Protected repCount
|
||||
Protected *c.Character = @toEncode
|
||||
|
||||
prevChar = Chr(*c\c)
|
||||
repCount = 1
|
||||
|
||||
*c + SizeOf(Character)
|
||||
While *c\c <> #Null
|
||||
currChar = Chr(*c\c)
|
||||
If currChar <> prevChar
|
||||
output + Str(repCount) + prevChar
|
||||
prevChar = currChar
|
||||
repCount = 1
|
||||
Else
|
||||
repCount + 1
|
||||
EndIf
|
||||
*c + SizeOf(Character)
|
||||
Wend
|
||||
|
||||
output + Str(repCount)
|
||||
output + prevChar
|
||||
ProcedureReturn output
|
||||
EndProcedure
|
||||
|
||||
If OpenConsole()
|
||||
Define initial.s, encoded.s, decoded.s
|
||||
|
||||
Print("Type something: ")
|
||||
initial = Input()
|
||||
encoded = RLEncode(initial)
|
||||
decoded = RLDecode(encoded)
|
||||
PrintN(initial)
|
||||
PrintN(RLEncode(initial))
|
||||
PrintN(RLDecode(encoded))
|
||||
|
||||
Print(#CRLF$ + #CRLF$ + "Press ENTER to exit")
|
||||
Input()
|
||||
CloseConsole()
|
||||
EndIf
|
||||
Loading…
Add table
Add a link
Reference in a new issue