Determine if a string is squeezable: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
(Added solution for Action!) |
||
Line 319: | Line 319: | ||
72<<< --- Harry S Truman >>> |
72<<< --- Harry S Truman >>> |
||
71<<< --- Hary S Truman >>></pre> |
71<<< --- Hary S Truman >>></pre> |
||
=={{header|Action!}}== |
|||
<lang Action!>PROC Squeeze(CHAR ARRAY in,out CHAR a) |
|||
BYTE i,j |
|||
CHAR c |
|||
j=1 c=0 |
|||
FOR i=1 TO in(0) |
|||
DO |
|||
IF in(i)#c OR in(i)#a THEN |
|||
c=in(i) |
|||
out(j)=c |
|||
j==+1 |
|||
FI |
|||
OD |
|||
out(0)=j-1 |
|||
RETURN |
|||
PROC Test(CHAR ARRAY s CHAR a) |
|||
CHAR ARRAY c(100) |
|||
BYTE CH=$02FC ;Internal hardware value for last key pressed |
|||
Squeeze(s,c,a) |
|||
PrintF("Character to squeeze: ""%C""%E",a) |
|||
PrintF("<<<%S>>> (len=%B)%E",s,s(0)) |
|||
PrintF("<<<%S>>> (len=%B)%E",c,c(0)) |
|||
PutE() |
|||
PrintE("Press any key to continue") |
|||
PutE() |
|||
DO UNTIL CH#$FF OD |
|||
CH=$FF |
|||
RETURN |
|||
PROC Main() |
|||
Test("",' ) |
|||
Test("""If I were two-faced, would I be wearing this one?"" --- Abraham Lincoln ",'-) |
|||
Test("..1111111111111111111111111111111111111111111111111111111111111117777888",'7) |
|||
Test("I never give 'em hell, I just tell the truth, and they think it's hell. ",'.) |
|||
Test(" --- Harry S Truman ",' ) |
|||
Test(" --- Harry S Truman ",'-) |
|||
Test(" --- Harry S Truman ",'r) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Determine_if_a_string_is_squeezable.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
Character to squeeze: " " |
|||
<<<>>> (len=0) |
|||
<<<>>> (len=0) |
|||
Character to squeeze: "-" |
|||
<<<"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln >>> (len=72) |
|||
<<<"If I were two-faced, would I be wearing this one?" - Abraham Lincoln >>> (len=70) |
|||
Character to squeeze: "7" |
|||
<<<..1111111111111111111111111111111111111111111111111111111111111117777888>>> (len=72) |
|||
<<<..1111111111111111111111111111111111111111111111111111111111111117888>>> (len=69) |
|||
Character to squeeze: "." |
|||
<<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> (len=72) |
|||
<<<I never give 'em hell, I just tell the truth, and they think it's hell. >>> (len=72) |
|||
Character to squeeze: " " |
|||
<<< --- Harry S Truman >>> (len=72) |
|||
<<< --- Harry S Truman >>> (len=20) |
|||
Character to squeeze: "-" |
|||
<<< --- Harry S Truman >>> (len=72) |
|||
<<< - Harry S Truman >>> (len=70) |
|||
Character to squeeze: "r" |
|||
<<< --- Harry S Truman >>> (len=72) |
|||
<<< --- Hary S Truman >>> (len=71) |
|||
</pre> |
|||
=={{header|Ada}}== |
=={{header|Ada}}== |