Determine if a string is collapsible: Difference between revisions

Content added Content deleted
(Determine if a string is collapsible en FreeBASIC)
Line 1,030: Line 1,030:
After collapse: «««😍😀🙌💃😍🙌»»» (length 6)
After collapse: «««😍😀🙌💃😍🙌»»» (length 6)
</pre>
</pre>


=={{header|FreeBASIC}}==
{{trans|BASIC}}
<lang freebasic>Const numCad = 5
Data ""
Data "'If I were two-faced, would I be wearing this one?' --- Abraham Lincoln "
Data "..1111111111111111111111111111111111111111111111111111111111111117777888"
Data "I never give 'em hell, I just tell the truth, and they think it's hell. "
Data " --- Harry S Truman "

Dim Shared As String cadIN, cadOUT

Sub Collapse
Dim As String a, b
If cadIN = "" Then cadOUT = cadIN: Exit Sub
cadOUT = Space(Len(cadIN))
a = Left(cadIN,1)
Mid(cadOUT,1,1) = a
Dim As Integer txtOUT = 2
For i As Integer = 2 To Len(cadIN)
b = Mid(cadIN,i,1)
If a <> b Then Mid(cadOUT,txtOUT,1) = b: txtOUT += 1: a = b
Next i
cadOUT = Left(cadOUT,txtOUT-1)
End Sub

For j As Integer = 1 To numCad
Read cadIN
Collapse
Print " <<<"; cadIN; ">>> (longitud "; Len(cadIN); _
!")\n se pliega a:\n <<<"; cadOUT; ">>> (longitud "; Len(cadOUT); !")\n"
Next j
Sleep
</lang>
{{out}}
<pre>
<<<>>> (longitud 0)
se pliega a:
<<<>>> (longitud 0)

<<<'If I were two-faced, would I be wearing this one?' --- Abraham Lincoln >>> (longitud 72)
se pliega a:
<<<'If I were two-faced, would I be wearing this one?' - Abraham Lincoln >>> (longitud 70)

<<<..1111111111111111111111111111111111111111111111111111111111111117777888>>> (longitud 72)
se pliega a:
<<<.178>>> (longitud 4)

<<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> (longitud 72)
se pliega a:
<<<I never give 'em hel, I just tel the truth, and they think it's hel. >>> (longitud 69)

<<< --- Harry S Truman >>> (longitud 72)
se pliega a:
<<< - Hary S Truman >>> (longitud 17)
</pre>



=={{header|Go}}==
=={{header|Go}}==