Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
77
Task/Run-length-encoding/BASIC256/run-length-encoding.basic
Normal file
77
Task/Run-length-encoding/BASIC256/run-length-encoding.basic
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
function FBString(lon, cad$)
|
||||
# Definimos la función String en BASIC256
|
||||
cadena$ = ""
|
||||
for a = 1 to lon
|
||||
cadena$ += cad$
|
||||
next a
|
||||
return cadena$
|
||||
end function
|
||||
|
||||
function RLDecode(i$)
|
||||
rCount$ = "" : outP$ = ""
|
||||
|
||||
for Loop0 = 1 to length(i$)
|
||||
m$ = mid(i$, Loop0, 1)
|
||||
begin case
|
||||
case m$ = "0"
|
||||
rCount$ += m$
|
||||
case m$ = "1"
|
||||
rCount$ += m$
|
||||
case m$ = "2"
|
||||
rCount$ += m$
|
||||
case m$ = "3"
|
||||
rCount$ += m$
|
||||
case m$ = "4"
|
||||
rCount$ += m$
|
||||
case m$ = "5"
|
||||
rCount$ += m$
|
||||
case m$ = "6"
|
||||
rCount$ += m$
|
||||
case m$ = "7"
|
||||
rCount$ += m$
|
||||
case m$ = "8"
|
||||
rCount$ += m$
|
||||
case m$ = "9"
|
||||
rCount$ += m$
|
||||
else
|
||||
if length(rCount$) then
|
||||
outP$ += FBString(int(rCount$), m$)
|
||||
rCount$ = ""
|
||||
else
|
||||
outP$ += m$
|
||||
end if
|
||||
end case
|
||||
next Loop0
|
||||
|
||||
RLDecode = outP$
|
||||
end function
|
||||
|
||||
function RLEncode(i$)
|
||||
outP$ = ""
|
||||
tmp1 = mid(i$, 1, 1)
|
||||
tmp2 = tmp1
|
||||
rCount = 1
|
||||
|
||||
for Loop0 = 2 to length(i$)
|
||||
tmp1 = mid(i$, Loop0, 1)
|
||||
if tmp1 <> tmp2 then
|
||||
outP$ += string(rCount) + tmp2
|
||||
tmp2 = tmp1
|
||||
rCount = 1
|
||||
else
|
||||
rCount += 1
|
||||
end if
|
||||
next Loop0
|
||||
|
||||
outP$ += replace(string(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