Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
54
Task/Run-length-encoding/FreeBASIC/run-length-encoding.basic
Normal file
54
Task/Run-length-encoding/FreeBASIC/run-length-encoding.basic
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
Dim As String initial, encoded, decoded
|
||||
|
||||
Function RLDecode(i As String) As String
|
||||
Dim As Long Loop0
|
||||
dim as string rCount, outP, m
|
||||
|
||||
For Loop0 = 1 To Len(i)
|
||||
m = Mid(i, Loop0, 1)
|
||||
Select Case m
|
||||
Case "0" To "9"
|
||||
rCount += m
|
||||
Case Else
|
||||
If Len(rCount) Then
|
||||
outP += String(Val(rCount), m)
|
||||
rCount = ""
|
||||
Else
|
||||
outP += m
|
||||
End If
|
||||
End Select
|
||||
Next
|
||||
RLDecode = outP
|
||||
End Function
|
||||
|
||||
Function RLEncode(i As String) As String
|
||||
Dim As String tmp1, tmp2, outP
|
||||
Dim As Long Loop0, rCount
|
||||
|
||||
tmp1 = Mid(i, 1, 1)
|
||||
tmp2 = tmp1
|
||||
rCount = 1
|
||||
|
||||
For Loop0 = 2 To Len(i)
|
||||
tmp1 = Mid(i, Loop0, 1)
|
||||
If tmp1 <> tmp2 Then
|
||||
outP += Ltrim(Rtrim(Str(rCount))) + tmp2
|
||||
tmp2 = tmp1
|
||||
rCount = 1
|
||||
Else
|
||||
rCount += 1
|
||||
End If
|
||||
Next
|
||||
|
||||
outP += Ltrim(Rtrim(Str(rCount)))
|
||||
outP += tmp2
|
||||
RLEncode = outP
|
||||
End Function
|
||||
|
||||
Input "Type something: ", initial
|
||||
encoded = RLEncode(initial)
|
||||
decoded = RLDecode(encoded)
|
||||
Print initial
|
||||
Print encoded
|
||||
Print decoded
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue