Odd word problem: Difference between revisions

m
 
(14 intermediate revisions by 8 users not shown)
Line 675:
readln;
end.</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
global inpi inp$ .
func$ read .
inpi += 1
return substr inp$ inpi 1
.
func ispunct c$ .
if c$ = "." or c$ = ":" or c$ = ";" or c$ = ","
return 1
.
return 0
.
func$ handle odd .
c$ = read
if ispunct c$ = 1
return c$
.
if odd = 0
write c$
r$ = handle 0
return r$
else
r$ = handle 1
write c$
return r$
.
.
proc go . .
repeat
c$ = handle odd
write c$
until c$ = "."
odd = 1 - odd
.
print ""
.
repeat
inp$ = input
until inp$ = ""
inpi = 0
go
.
input_data
we,are;not,in,kansas;any,more.
what,is,the;meaning,of:life.
 
</syntaxhighlight>
 
=={{header|EchoLisp}}==
Line 964 ⟶ 1,013:
 
If the ADVANCE feature is unavailable, then the file could be read as UNFORMATTED, one character at a go with a record length of one. And then would arise the annoyance of dealing with the ASCII world's usage of CR, CRLF, LFCR, or CR as markers for the ends of records.
 
=={{header|FreeBASIC}}==
Rosetta Code problem: https://rosettacode.org/wiki/Odd_word_problem
by Jjuanhdez, 05/2023
<syntaxhighlight lang="vb">Dim Shared As Integer n1 = 1
 
Function reverseString(texto As String) As String
Dim As Integer x, lt = Len(texto)
For x = 0 To lt Shr 1 - 1
Swap texto[x], texto[lt - x - 1]
Next x
Return texto
End Function
 
Sub process(texto As String)
Dim As Integer c = 0, n2
Dim As String tmptexto
Print "Input stream: "; texto
Print "Output stream: ";
Do
n2 = Instr(texto, Any ",;:.")
tmptexto = Mid(texto, n1, n2-1)
Print Iif(c Mod 2 = 0, tmptexto, reverseString(tmptexto)); Mid(texto, n2, 1);
If Mid(texto, n2, 1) = "." Then Exit Do
texto = Mid(texto, n2+1, Len(texto))
c += 1
Loop
Print !"\n"
End Sub
 
process("what,is,the;meaning,of:life.")
process("we,are;not,in,kansas;any,more.")
 
Sleep</syntaxhighlight>
{{out}}
<pre>Input stream: what,is,the;meaning,of:life.
Output stream: what,si,the;gninaem,of:efil.
 
Input stream: we,are;not,in,kansas;any,more.
Output stream: we,era;not,ni,kansas;yna,more.</pre>
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
begin globals
short ndx : bool odd : cfstringref stream
end globals
 
local fn recursion
cfstringref ch = mid( stream, ndx, 1 )
if fn StringContainsString( @",;:. ", ch ) == no
ndx++
if odd then fn recursion : print ch; ¬
else print ch; : fn recursion
end if
end fn
 
local fn oddWordTask( s as cfstringref )
ndx = 0 : odd = no : stream = s
print : print, stream : print,
while ndx < len( stream )
fn recursion : print mid( stream, ndx, 1 );
odd = yes - odd : ndx++
wend
print
end fn
 
window 1, @"Odd word task in FutureBasic", (0,0,310,155)
fn oddWordTask( @"what,is,the;meaning,of:life." )
fn oddWordTask( @"we,are;not,in,kansas;any,more." )
fn oddWordTask( @"This also works with normal spaces." )
 
HandleEvents
</syntaxhighlight>
{{output}}
[[File:FB output for Odd Word Task.png]]
 
=={{header|Go}}==
Line 2,900 ⟶ 3,027:
Second way : what,si,the;gninaem,of:efil.</pre>
 
=={{header|V (Vlang)}}==
<syntaxhighlight lang="v (vlang)">
const str = 'what,is,the;meaning,of:life.'
 
Line 2,936 ⟶ 3,063:
{{trans|Kotlin}}
{{libheader|Wren-str}}
<syntaxhighlight lang="ecmascriptwren">import "io" for Stdin,Stdout
import "./str" for Char
 
var fwrite = Fn.new { |ch|
Line 2,979 ⟶ 3,106:
we,era;not,ni,kansas;yna,more.
 
</pre>
 
=={{header|XPL0}}==
{{trans|Go}}
<syntaxhighlight lang "XPL0">proc OWP;
int B;
func Odd;
int S, B;
[S:= ChIn(8);
if S < ^A then \punct\ return S;
B:= Odd;
ChOut(0, S);
return B;
];
 
[OpenI(8);
loop [loop [B:= ChIn(8);
ChOut(0, B);
if B = ^. then return;
if B < ^A \punct\ then quit;
];
B:= Odd;
ChOut(0, B);
if B = ^. then return;
];
];
 
[OpenO(8);
Text(8, "what,is,the;meaning,of:life. ");
OWP;
CrLf(0);
 
OpenO(8);
Text(8, "we,are;not,in,kansas;any,more. ");
OWP;
CrLf(0);
]</syntaxhighlight>
{{out}}
<pre>
what,si,the;gninaem,of:efil.
we,era;not,ni,kansas;yna,more.
</pre>
 
2,060

edits