String excercises
E01
Given two strings of the same length (passed as constant references), return the number of characters in corresponding positions in which they differ.
For example:
"casa"
differs from"cosa"
in 1 position."abc"
differs from"cab"
in all 3 positions"elefante"
differents from"elefante"
in 0 positions
Do not use any function from the string class except length
(and []
to access the characters)
E02
Given two strings of the same length (passed as constant references), return true
if one can be obtained from the other by swapping exactly two characters. For example,
"cosa"
,"caso"
would returntrue
"abc"
,"cba"
would returntrue
"xyz"
,"xab"
would returnfalse
"cotorra"
,"corotra"
would returntrue
"a"
,"b"
would returnfalse
Do not use any function from the string class except length
(and []
to access the characters)
E03
A string is considered an abbreviation of a word if we can form the word by inserting zero o more letters at the beginning, end or between the characters of the abbreviation. For example:
-
"gtr"
is an abbreviation of"guitar"
-
"bne"
is an abbreviation of"trombone"
,"bone"
,"binder"
and many other words -
"pai"
is not abbreviation of "piano" because the piano contains p, a, i in another -
"pai"
is an abbreviation of"paint"
,"polarity"
, "apartheid", and many others
Write a function bool abbreviation(const string &abrev, const string &word)
that receives two strings and returns true if the first is an abbreviation of the second
Do not use any function from the string class except length
(and []
to access the characters)