How to resolve the algorithm Odd word problem step by step in the V (Vlang) programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Odd word problem step by step in the V (Vlang) 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 V (Vlang) programming language
Source code in the v programming language
const str = 'what,is,the;meaning,of:life.'
fn main() {
mut temp, mut new_str := '', ''
mut switch := true
for field in str {
temp += field.ascii_str()
if field.is_alnum() == false {
if switch == true {
new_str += temp
temp =''
switch = false
continue
}
else {
new_str += temp.all_before_last(field.ascii_str()).reverse() + field.ascii_str()
temp =''
switch = true
continue
}
}
}
println(new_str)
}
You may also check:How to resolve the algorithm String matching step by step in the Ada programming language
You may also check:How to resolve the algorithm Boolean values step by step in the Insitux programming language
You may also check:How to resolve the algorithm ASCII art diagram converter step by step in the REXX programming language
You may also check:How to resolve the algorithm Literals/String step by step in the Objective-C programming language
You may also check:How to resolve the algorithm ISBN13 check digit step by step in the Action! programming language