Back to Editorials CodeCraft β
  • Github
  • Instagram
< >

Encryption

TIME LIMIT = 1 SEC.

  • All the digital communication around is encrypted for security. Encryption is necessary as privacy is a human right. In college, you are in charge of encrypting sensitive messages.
    The rule for encryption is as follows: If the given word is a palindrome, then perform left shift operation once on that word. If the given word is not a palindrome, then perform right shift twice on that word.
    NOTE: Left shift indicates that each character is shifted to the left i.e. C becomes B, B becomes A and A becomes Z and so on.Right shift indicates that each character is shifted to the right i.e. A becomes B, B becomes C and Z becomes A and so on.
Input Output
First line will contain N, number of words.
Each of the next N lines contains one word (in lowercase), whose length does not exceed 50.
Print the corresponding shifted word for each of the given words according to the rule above.
Constraints
  • 1 ≤ N ≤ 200
Example Test Case
Input             Output
3
malayalam
hello
rotor

lzkzxzkzl
jgnnq
qnsnq
Solution

#include <iostream> #include <string> #include <algorithm> using namespace std; string leftShift(string str) { for(int i =0;i<str.length();i++) { if(str[i]=='a') str[i]='z'; else str[i]-=1; } return str; } string rightShift(string str) { for(int i =0;i<str.length();i++) { if(str[i]=='y') str[i]='a'; if(str[i]=='z') str[i]='b'; else str[i]+=2; } return str; } int main() { int n,i; cin>>n; string ip[n],temp; for(i=0;i<n;i++) { cin>>ip[i]; temp = ip[i]; reverse(temp.begin(),temp.end()); if(temp==ip[i]) ip[i] = leftShift(ip[i]); else ip[i] = rightShift(ip[i]); } for(i=0;i<n;i++) cout<<ip[i]<<endl; return 0; }
  • #1 Thieves
  • #2 The Queue of Doubts
  • #3 Summation of Primes
  • #4 Spacious Maximus
  • #5 Samosas
  • #6 Reasonably Sound
  • #7 Product of Digits
  • #8 Prime Usernames
  • #9 Path Shifter
  • #10 Keypad Count
  • #11 Even Vowels
  • #12 Encryption
  • #13 Decryption
  • #14 Canteen Accountant
  • #15 Attendance Register
  • #16 Amazing Year

Get in touch

  • executives@codingstudio.club
  • +91 9010342360
  • Vignana Bharthi Instute of Technology
    Aushapur, Ghatkesar, Hyderabad, Telengana - India

© coding.Studio();