How to resolve the algorithm Odd word problem step by step in the OCaml programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Odd word problem step by step in the OCaml programming language
Table of Contents
Problem Statement
Write a program that solves the odd word problem with the restrictions given below.
You are promised an input stream consisting of English letters and punctuations.
It is guaranteed that:
A stream with six words:
The task is to reverse the letters in every other word while leaving punctuations intact, producing: while observing the following restrictions:
Work on both the "life" example given above, and also the text:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Odd word problem step by step in the OCaml programming language
Source code in the ocaml programming language
let is_alpha c =
c >= 'a' && c <= 'z' ||
c >= 'A' && c <= 'Z'
let rec odd () =
let c = input_char stdin in
if is_alpha c
then (let e = odd () in print_char c; e)
else (c)
let rec even () =
let c = input_char stdin in
if is_alpha c
then (print_char c; even ())
else print_char c
let rev_odd_words () =
while true do
even ();
print_char (odd ())
done
let () =
try rev_odd_words ()
with End_of_file -> ()
You may also check:How to resolve the algorithm Anagrams step by step in the NewLisp programming language
You may also check:How to resolve the algorithm Prime numbers whose neighboring pairs are tetraprimes step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the REXX programming language
You may also check:How to resolve the algorithm Define a primitive data type step by step in the Toka programming language
You may also check:How to resolve the algorithm Rot-13 step by step in the Pike programming language