Click here to Skip to main content
15,889,200 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
For example:
"the ace deck" should become "gsv zxv wvxp".
a replaced by z,
b replaced by y,
c replaced by x,
and so on.
Incase of uppercase letters...replacement differs.
This was asked in an technical written test.Someone help me out knowing the code for it
Posted
Comments
Kornfeld Eliyahu Peter 10-May-15 6:50am    
And z replaced by what?
Abhipal Singh 10-May-15 9:01am    
I believe 'z' should be replaced by 'a' as per the pattern given
Kornfeld Eliyahu Peter 10-May-15 9:09am    
Maybe, but when the replace pattern is circular you should address the problem differently from the case when it is not...So an answer with the full pattern would be welcome...
Abhipal Singh 10-May-15 9:19am    
I agree with you

As we all know, there are 26 chars in English.

(and assuming z is replaced by a)

Follow the below steps:

1) Treat each character as a number, like
a as 0
b as 1
c as 2 and so on. (Hint: Enumerations)

2) Subtract the number you get from 25 (not 26 as we are starting from 0).

3) Result of above (pt. 2) is your new character.

Can't comment on upper case problem as you have not specified it.
 
Share this answer
 
v2
Is not good to supply code for a test where you have to be evaluated. But pointing out a way could be ammissible...
1 - Create maps of characters conversion (one for lower case and the other for uppercase), or figure an algorithm to convert one char to the other (i.e. if lowercase characters are reversed: NewChar = 'z' - (25-(Char-'a')).
2 - Create a loop scanning all your string char by char
3 - For each char check if it is uppercase, if yes use the conversion for uppercase, else for lowercase.
4 - replace the char in the string
5 - Done
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900