CHO1 - Editorial

PROBLEM LINK:

Practice

Contest

Author: Manisha Reddy Thirumala Reddy

Tester: Manisha Reddy Thirumala Reddy

DIFFICULTY:

CAKEWALK.

PREREQUISITES:

Strings, Arrays.

PROBLEM:

Given a string s with n characters, we need to perform the following steps:

  • swap adjacent characters.
  • swap every alphabet with its ASCII reverse alphabet. Ex: For ‘a’ the reverse ASCII value is ‘z’.
    we can do this by ASCII values (char)(122-‘a’+97) = ‘z’.

EXPLANATION:

As it is very easy question, the code snippet will guide you.


 for(int i=0; i<len; i = i+2){

       temp = en[i+1];
        en[i+1]=en[i];
        en[i]=temp;
}

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.

Nice chance to use a dictionary in Python.

alph = 'abcdefghijklmnopqrstuvwxyz'
cbk = dict()
for ch in range(26):
    cbk[alph[ch]] = alph[25-ch]

PS: the puzzle code for the practice version is ENCMSG (for searchers).