I am developing an aplication called Mirror().The mirror image of string vow is
ID: 3548864 • Letter: I
Question
I am developing an aplication called Mirror().The mirror image of string vow is string wov, and the mirror image wood is string boow. The mirror image of string bed cannot be represented as a string, however, because the mirror image of e is not a valid character. This function mirror( ) should take a string and return it's mirror image, so long as the mirror image can be represented using valid characters.
* Ok, My guess is that I should find a way to reverse the characters of a given string and then create a dictionary that contains a list of valid characters, checking if each letter is within the dictionary of valid characters.
*How can I approach the subproblem of reversing a string? What measures or strageties should I take?
Explanation / Answer
create a char array of valid_mirror characters like {b,d,i,l,m,o,p,q,u,v,w,x}
for reverse, we will swap the first and last element first, then second and second last element, then third and third last until we reach the middle of the word.
char temp;
void swap(char[] x)
{
//Add a condition here to check if the char can be mirrored
for(int i=0;i<x.length()/2;i++)
{
temp = x[i];
x[i] = x[ x.length() - i ];
x[ x.length() - i ] = temp;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.