It simply takes the string as input and encode in the two steps- index 1 and 2 are swapped,index 3 and 4 ,index 5 and 6...and so on.if the string is of odd length;then the last character remain as it is.After step1, letters are encoded accordingly- a to z,z to a,b to y..and so on
#include <iostream>
using namespace std;
char* encode(char* word,int N);
void swap(char* a,char* b);
int main()
{
int T,N;
cin>>T;
char word[100];
while(T)
{
cin>>N;
//char word[N];
for(int i=0;i<N;i++)
cin>>word[i];
cout<<encode(word,N)<<"\n";
for(int i=0;i<N;i++)
word[i]=' ';
T--;
}
return 0;
}
char* encode(char* word,int N)
{
int length;
N%2==0?length=N:length=N-1;
if(N%2!=0)
word[N-1]=char(219-word[N-1]);
for(int i=0;i<length;i=i+2)
{
swap(word[i],word[i+1]);
word[i]=char(219-word[i]);
word[i+1]=char(219-word[i+1]);
}
return word;
}
void swap(char* a,char* b)
{
char* temp;
temp=b;
b=a;
a=temp;
}